Exemple #1
0
 def post(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         name = request.POST.get('name')
         start_place = request.POST.get('startPlace')
         end_place = request.POST.get('endPlace')
         time = request.POST.get('time')
         # 片区id组合起来德字符串,例如:'1-2-3-4-5'
         district_str = request.POST.get('districtStr', '')
         remark_1 = request.POST.get('remark1', '')
         remark_2 = request.POST.get('remark2', '')
         remark_3 = request.POST.get('remark3', '')
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_service_line = ServiceLine(name=name, startPlace=start_place, endPlace=end_place,
                                                   time=time, remark1=remark_1, remark2=remark_2, remark3=remark_3)
     try:
         with transaction.atomic():
             cur_service_line.save()
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                        status.HTTP_500_INTERNAL_SERVER_ERROR)
     district_list = []
     if district_str:
         district_list = district_str.split('-')
     print(district_list)
     for item in district_list:
         cur_district = District.objects.get(id=int(item))
         cur_service_line.district.add(cur_district)
     return Response(response_data, status.HTTP_200_OK)
Exemple #2
0
    def delete(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            section_id = int(request.POST.get('sectionId'))
            station_id = int(request.POST.get('stationId'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        cur_station = Station.objects.get(id=station_id)
        cur_station.section_id = None
        try:
            with transaction.atomic():
                cur_station.save()
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_SAVE_INFO_FAIL,
                status.HTTP_500_INTERNAL_SERVER_ERROR)
        # 路的段/岗数量更新
        road_id = Section.objects.get(id=section_id).road_id
        if road_id:
            guard_road.objects.filter(uid=road_id + increment).update(
                stationnum=F('stationnum') - 1)

        return Response(response_data, status.HTTP_200_OK)
Exemple #3
0
    def post(self, request):
        response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
        try:
            road_id = int(request.POST.get('roadId'))
            section_id = int(request.POST.get('sectionId'))
            # rank=1: upgrade; rank=2: downgrade
            rank = int(request.POST.get('rank'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
        cur_road = Road.objects.get(id=road_id)
        sections_ids = cur_road.sectionids
        if not sections_ids:
            return generate_error_response(error_constants.ERR_NO_SECTION_IN_ROAD, status.HTTP_400_BAD_REQUEST)
        section_id_list = sections_ids.split('-')
        if len(section_id_list) == 1:
            return generate_error_response(error_constants.ERR_ONE_SECTION_IN_ROAD, status.HTTP_400_BAD_REQUEST)
        index = section_id_list.index(str(section_id))
        if index == 0 and rank == 1:
            return generate_error_response(error_constants.ERR_SECTION_FIRST, status.HTTP_400_BAD_REQUEST)
        if index == len(section_id_list)-1 and rank == 2:
            return generate_error_response(error_constants.ERR_SECTION_LAST, status.HTTP_400_BAD_REQUEST)
        if rank == 1:
            section_id_list[index-1], section_id_list[index] = section_id_list[index], section_id_list[index-1]
        if rank == 2:
            section_id_list[index], section_id_list[index+1] = section_id_list[index+1], section_id_list[index]

        cur_road.sectionids = '-'.join(section_id_list)
        with transaction.atomic():
            cur_road.save()
        return Response(response_data, status.HTTP_200_OK)
Exemple #4
0
 def get(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
     }
     try:
         faculty_id = int(request.GET.get('facultyId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     cur_faculty = Faculty.objects.get(id=faculty_id)
     cur_faculty.enabled = False
     try:
         with transaction.atomic():
             cur_faculty.save()
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     return Response(response_data, status.HTTP_200_OK)
Exemple #5
0
    def post(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1],
            'data': {
                'userName': '',
                'token': '',
            }
        }
        try:
            user_name = request.POST.get('userName', '')
            password = request.POST.get('password', '')
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)

        pass_word_hash = hashlib.md5(password).hexdigest()
        cur_account = Account.objects.filter(name=user_name,
                                             password=pass_word_hash).first()
        if not cur_account:
            return generate_error_response(error_constants.ERR_INVALID_ACCOUNT,
                                           status.HTTP_400_BAD_REQUEST)
        token = create_token(user_name)
        response_data['data']['userName'] = user_name
        response_data['data']['token'] = token
        response_data['data']['districtId'] = cur_account.district_id
        return Response(response_data, status.HTTP_200_OK)
Exemple #6
0
 def put(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1],
     }
     try:
         user_name = request.POST.get('userName')
         old_password = request.POST.get('oldPassword')
         new_password = request.POST.get('newPassword')
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     cur_account = Account.objects.filter(name=user_name)
     if cur_account.first().password != hashlib.md5(
             old_password).hexdigest():
         return generate_error_response(error_constants.ERR_INVALID_ACCOUNT,
                                        status.HTTP_400_BAD_REQUEST)
     if old_password == new_password:
         return generate_error_response(
             error_constants.ERR_INVALID_NEW_PASSWORD,
             status.HTTP_400_BAD_REQUEST)
     cur_account.update(password=hashlib.md5(new_password).hexdigest())
     return Response(response_data, status.HTTP_200_OK)
Exemple #7
0
 def post(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         section_id = int(request.POST.get('sectionId'))
         # faculty_id = int(request.POST.get('facultyId'))
         name = request.POST.get('name', '')
         mobile = request.POST.get('mobile', '')
         duty = request.POST.get('duty', '')
         channel = request.POST.get('channel', '')
         call_sign = request.POST.get('callSign', '')
         district_id = int(request.POST.get('districtId', 0))
         # faculty_type 1 段长;2 执行段长 分局;3: 执行段长 交通;4:执行段长 武警
         faculty_type = int(request.POST.get('facultyType'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_section = Section.objects.get(id=section_id)
     cur_faculty = Faculty.objects.filter(name=name, mobile=mobile)
     if cur_faculty.exists():
         cur_faculty.update(enabled=True)
         cur_faculty = cur_faculty.first()
     else:
         cur_faculty = Faculty(name=name, mobile=mobile, duty=duty, main_name=cur_section.name,
                                              level=2, role=faculty_type, main_id=section_id,
                                              district_id=cur_section.district_id, channel=cur_section.channel,
                                              call_sign=cur_section.call_sign)
         # 岗位人数限制
         count = check_faculty_count_particular_role(cur_faculty)
         if faculty_type == 1:
             count1 = cur_section.chief.filter(enabled=True).count()
         if faculty_type == 2:
             count1 = cur_section.exec_chief_sub_bureau.filter(enabled=True).count()
         if faculty_type == 3:
             count1 = cur_section.exec_chief_trans.filter(enabled=True).count()
         if faculty_type == 4:
             count1 = cur_section.exec_chief_armed_poli.filter(enabled=True).count()
         print 'section people_count:', count1
         if count >= 4 or count1 >= 4:
             return generate_error_response(error_constants.ERR_FACULTY_EXCEED_COUNT, status.HTTP_400_BAD_REQUEST)
         else:
             try:
                 with transaction.atomic():
                     cur_faculty.save()
             except Exception as ex:
                 print 'function name: ', __name__
                 print Exception, ":", ex
                 return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                                status.HTTP_500_INTERNAL_SERVER_ERROR)
     if faculty_type == 1:
         cur_section.chief.add(cur_faculty)
     if faculty_type == 2:
         cur_section.exec_chief_sub_bureau.add(cur_faculty)
     if faculty_type == 3:
         cur_section.exec_chief_trans.add(cur_faculty)
     if faculty_type == 4:
         cur_section.exec_chief_armed_poli.add(cur_faculty)
     return Response(response_data, status.HTTP_200_OK)
Exemple #8
0
 def post(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
     }
     try:
         road_id = int(request.POST.get('roadId'))
         name = request.POST.get('name')
         length = request.POST.get('length', '')
         start_place = request.POST.get('startPlace')
         end_place = request.POST.get('endPlace')
         channel = request.POST.get('channel', '')
         call_sign = request.POST.get('callSign', '')
         remark_1 = request.POST.get('remark1', '')
         remark_2 = request.POST.get('remark2', '')
         remark_3 = request.POST.get('remark3', '')
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     cur_road = Road.objects.get(id=road_id)
     district_id = cur_road.district_id
     new_road = Road(name=name,
                     start_place=start_place,
                     end_place=end_place,
                     length=length,
                     remark1=remark_1,
                     remark2=remark_2,
                     channel=channel,
                     call_sign=call_sign,
                     remark3=remark_3,
                     district_id=district_id)
     try:
         with transaction.atomic():
             new_road.save()
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_SAVE_INFO_FAIL,
             status.HTTP_500_INTERNAL_SERVER_ERROR)
     chief = cur_road.chief.all()
     bureau = cur_road.exec_chief_sub_bureau.all()
     trans = cur_road.exec_chief_trans.all()
     arm_poli = cur_road.exec_chief_armed_poli.all()
     for item in chief:
         new_road.chief.add(item)
     for item in bureau:
         new_road.exec_chief_sub_bureau.add(item)
     for item in trans:
         new_road.exec_chief_trans.add(item)
     for item in arm_poli:
         new_road.exec_chief_armed_poli.add(item)
     # 段的复制
     copy_section_to_new_road(new_road, cur_road)
     return Response(response_data, status.HTTP_200_OK)
Exemple #9
0
    def post(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            station_id = int(request.POST.get('stationId'))
            name = request.POST.get('name')
            location = request.POST.get('location')
            channel = request.POST.get('channel', '')
            call_sign = request.POST.get('callSign', '')
            remark_1 = request.POST.get('remark1', '')
            remark_2 = request.POST.get('remark2', '')
            remark_3 = request.POST.get('remark3', '')
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        cur_station = Station.objects.get(id=station_id)
        district_id = cur_station.district_id
        section_id = cur_station.section_id
        new_station = Station(name=name,
                              location=location,
                              channel=channel,
                              remark1=remark_1,
                              call_sign=call_sign,
                              remark2=remark_2,
                              remark3=remark_3,
                              district_id=district_id)
        try:
            with transaction.atomic():
                new_station.save()
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_SAVE_INFO_FAIL,
                status.HTTP_500_INTERNAL_SERVER_ERROR)
        chief = cur_station.chief.all()
        trans = cur_station.exec_chief_trans.all()
        for item in chief:
            new_station.chief.add(item)
        for item in trans:
            new_station.exec_chief_trans.add(item)

        # 路的段/岗数量更新
        if section_id:
            road_id = Section.objects.get(id=section_id).road_id
            if road_id:
                cur_guard_road = guard_road.objects.filter(uid=road_id +
                                                           increment)
                cur_guard_road.update(sectionnum=F('stationnum') + 1)
        return Response(response_data, status.HTTP_200_OK)
Exemple #10
0
    def post(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            service_line_id = int(request.POST.get('serviceLineId', 0))
            district_id = int(request.POST.get('districtId'))
            name = request.POST.get('name')
            length = request.POST.get('length', '')
            start_place = request.POST.get('startPlace')
            end_place = request.POST.get('endPlace')
            channel = request.POST.get('channel', '')
            call_sign = request.POST.get('callSign', '')
            remark_1 = request.POST.get('remark1', '')
            remark_2 = request.POST.get('remark2', '')
            remark_3 = request.POST.get('remark3', '')
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        cur_road = Road(name=name,
                        length=length,
                        start_place=start_place,
                        channel=channel,
                        call_sign=call_sign,
                        end_place=end_place,
                        remark1=remark_1,
                        remark2=remark_2,
                        remark3=remark_3,
                        district_id=district_id)
        try:
            with transaction.atomic():
                cur_road.save()
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_SAVE_INFO_FAIL,
                status.HTTP_500_INTERNAL_SERVER_ERROR)
        if service_line_id:
            cur_service_line = ServiceLine.objects.get(id=service_line_id)
            cur_service_line.road.add(cur_road)
            # 更新勤务路线的roadids
            update_service_line_road_ids(service_line_id, cur_road.id, True)

        return Response(response_data, status=status.HTTP_200_OK)
Exemple #11
0
    def post(self, request):
        response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
        try:
            road_id = int(request.POST.get('roadId', 0))
            district_id = int(request.POST.get('districtId'))
            name = request.POST.get('name')
            start_place = request.POST.get('startPlace')
            end_place = request.POST.get('endPlace')
            xy_coordinate = request.POST.get('XYCOORDINATE', '')
            channel = request.POST.get('channel', '')
            call_sign = request.POST.get('callSign', '')
            remark_1 = request.POST.get('remark1', '')
            remark_2 = request.POST.get('remark2', '')
            remark_3 = request.POST.get('remark3', '')
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)

        if road_id:
            cur_section = Section(name=name, start_place=start_place, end_place=end_place,
                                                 xy_coordinate=xy_coordinate, road_id=road_id, channel=channel,
                                                 call_sign=call_sign, remark1=remark_1, remark2=remark_2,
                                                 remark3=remark_3, district_id=Road.objects.get(id=road_id).district_id)

            try:
                with transaction.atomic():
                    cur_section.save()
            except Exception as ex:
                print 'function name: ', __name__
                print Exception, ":", ex
                return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                               status.HTTP_500_INTERNAL_SERVER_ERROR)
            update_road_section_ids(road_id, cur_section.id, True)
        else:
            cur_section = Section(name=name, start_place=start_place,
                                                 end_place=end_place, xy_coordinate=xy_coordinate,
                                                 remark1=remark_1, channel=channel, call_sign=call_sign,
                                                 remark2=remark_2, remark3=remark_3, district_id=district_id)
            try:
                with transaction.atomic():
                    cur_section.save()
            except Exception as ex:
                print 'function name: ', __name__
                print Exception, ":", ex
                return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                               status.HTTP_500_INTERNAL_SERVER_ERROR)
        return Response(response_data, status=status.HTTP_200_OK)
Exemple #12
0
    def delete(self, request):
        response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
        try:
            road_id = int(request.data.get('roadId'))
            section_id = int(request.data.get('sectionId'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
        cur_section = Section.objects.get(id=section_id)
        cur_section.road_id = None
        with transaction.atomic():
            cur_section.save()

        # 更新road 的sectionids
        update_road_section_ids(road_id, section_id, False)

        # 路的段/岗数据更新
        station_num = cur_section.Section_Station.filter(enabled=True).count()
        cur_guard_road = guard_road.objects.get(uid=road_id + increment)
        cur_guard_road.sectionnum = cur_guard_road.sectionnum - 1
        cur_guard_road.stationnum = cur_guard_road.stationnum - station_num
        with transaction.atomic():
            cur_guard_road.save()
        return Response(response_data, status.HTTP_200_OK)
Exemple #13
0
 def post(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         service_line_id = int(request.POST.get('serviceLineId'))
         district_id = int(request.POST.get('districtId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_service_line = ServiceLine.objects.get(id=service_line_id)
     submit_district = cur_service_line.submit_district
     if not submit_district:
         submit_district = submit_district + str(district_id)
     else:
         district_list = submit_district.split('-')
         if str(district_id) in district_list:
             pass
         else:
             district_list.append(str(district_id))
             submit_district = '-'.join(district_list)
     cur_service_line.submit_district = submit_district
     with transaction.atomic():
         cur_service_line.save()
     return Response(response_data, status.HTTP_200_OK)
Exemple #14
0
 def post(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         section_id = int(request.POST.get('sectionId'))
         faculty_id = int(request.POST.get('facultyId'))
         faculty_type = int(request.POST.get('facultyType'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_section = Section.objects.get(id=section_id)
     cur_faculty = Faculty.objects.get(id=faculty_id)
     if faculty_type == 1:
         cur_section.chief.add(cur_faculty)
     if faculty_type == 2:
         cur_section.exec_chief_sub_bureau.add(cur_faculty)
     if faculty_type == 3:
         cur_section.exec_chief_trans.add(cur_faculty)
     if faculty_type == 4:
         cur_section.exec_chief_armed_poli.add(cur_faculty)
     cur_faculty.channel = cur_section.channel
     cur_faculty.call_sign = cur_section.call_sign
     with transaction.atomic():
         cur_faculty.save()
     return Response(response_data, status.HTTP_200_OK)
Exemple #15
0
 def get(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1],
         'data': {
             'chiefList': [],
             'execChiefTransList': []
         }
     }
     try:
         station_id = int(request.GET.get('stationId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     cur_station = Station.objects.get(id=station_id)
     cur_station_name = cur_station.name
     district_id = cur_station.district_id
     chief_list = cur_station.chief.all().values_list('id', flat=True)
     trans_list = cur_station.exec_chief_trans.all().values_list('id',
                                                                 flat=True)
     cur_chief_list = Faculty.objects.filter(enabled=True, district_id=district_id,
                                             level=3, role=1, main_name=cur_station_name).\
         exclude(id__in=chief_list).order_by('id')
     cur_trans_list = Faculty.objects.filter(enabled=True, district_id=district_id,
                                             level=3, role=2, main_name=cur_station_name).\
         exclude(id__in=trans_list).order_by('id')
     response_data['data']['chiefList'] = FacultySerializer(cur_chief_list,
                                                            many=True).data
     response_data['data']['execChiefTransList'] = FacultySerializer(
         cur_trans_list, many=True).data
     return Response(response_data, status.HTTP_200_OK)
Exemple #16
0
 def get(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
     }
     try:
         road_id = int(request.GET.get('roadId'))
         faculty_id = int(request.GET.get('facultyId'))
         # faculty_type 1 路长;2 执行路长 分局;3: 执行路长 交通;4:执行路长 武警
         faculty_type = int(request.GET.get('facultyType'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     cur_road = Road.objects.get(id=road_id)
     cur_faculty = Faculty.objects.get(id=faculty_id)
     if faculty_type == 1:
         cur_road.chief.remove(cur_faculty)
     if faculty_type == 2:
         cur_road.exec_chief_sub_bureau.remove(cur_faculty)
     if faculty_type == 3:
         cur_road.exec_chief_trans.remove(cur_faculty)
     if faculty_type == 4:
         cur_road.exec_chief_armed_poli.remove(cur_faculty)
     return Response(response_data, status.HTTP_200_OK)
Exemple #17
0
 def put(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         select_districts_str = request.POST.get('selectDistrictsStr', '')
         service_line_id = int(request.POST.get('serviceLineId'))
         name = request.POST.get('name', '')
         start_place = request.POST.get('startPlace', '')
         end_place = request.POST.get('endPlace', '')
         time = request.POST.get('time', '')
         remark1 = request.POST.get('remark1', '')
         remark2 = request.POST.get('remark2', '')
         remark3 = request.POST.get('remark3', '')
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_service_line = ServiceLine.objects.get(id=service_line_id)
     cur_service_line.name = name
     cur_service_line.startPlace = start_place
     cur_service_line.endPlace = end_place
     cur_service_line.time = time
     cur_service_line.remark1 = remark1
     cur_service_line.remark2 = remark2
     cur_service_line.remark3 = remark3
     with transaction.atomic():
         cur_service_line.save()
     dis_list = []
     if select_districts_str:
         dis_list = select_districts_str.split('-')
     cur_service_line.district.clear()
     for item in dis_list:
         cur_dis = District.objects.get(id=int(item))
         cur_service_line.district.add(cur_dis)
     return Response(response_data, status.HTTP_200_OK)
Exemple #18
0
    def get(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1],
            'dataList': []
        }
        try:
            section_id = int(request.GET.get('sectionId'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        cur_section = Section.objects.get(id=section_id)
        # 当前路段district_id
        cur_section_district_id = cur_section.district_id
        # 当前路段岗位id
        cur_section_station_id_lists = cur_section.Section_Station.all(
        ).values_list('id', flat=True)

        cur_station_list = Station.objects.filter(
            enabled=True,
            district_id=cur_section_district_id,
            section_id__isnull=True).exclude(
                id__in=cur_section_station_id_lists)
        response_data['dataList'] = StationSerializer(cur_station_list,
                                                      many=True).data
        return Response(response_data, status.HTTP_200_OK)
Exemple #19
0
    def post(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            service_line_id = int(request.POST.get('serviceLineId'))
            road_id = int(request.POST.get('roadId'))
            # rank=1: upgrade; rank=2: downgrade
            rank = int(request.POST.get('rank'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        cur_service_line = ServiceLine.objects.get(id=service_line_id)
        road_ids = cur_service_line.roadids
        if not road_ids:
            return generate_error_response(
                error_constants.ERR_NO_ROAD_IN_SERVICELINE,
                status.HTTP_400_BAD_REQUEST)
        road_id_list = road_ids.split('-')
        if len(road_id_list) == 1:
            return generate_error_response(
                error_constants.ERR_ONE_ROAD_IN_SERVICELINE,
                status.HTTP_400_BAD_REQUEST)
        index = road_id_list.index(str(road_id))
        if index == 0 and rank == 1:
            return generate_error_response(error_constants.ERR_ROAD_FIRST,
                                           status.HTTP_400_BAD_REQUEST)
        if index == len(road_id_list) - 1 and rank == 2:
            print('already last')
            return generate_error_response(error_constants.ERR_ROAD_LAST,
                                           status.HTTP_400_BAD_REQUEST)
        if rank == 1:
            road_id_list[index - 1], road_id_list[index] = road_id_list[
                index], road_id_list[index - 1]
        if rank == 2:
            road_id_list[index], road_id_list[index + 1] = road_id_list[
                index + 1], road_id_list[index]

        cur_service_line.roadids = '-'.join(road_id_list)
        with transaction.atomic():
            cur_service_line.save()
        return Response(response_data, status.HTTP_200_OK)
Exemple #20
0
    def put(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            faculty_id = request.POST.get('facultyId')
            name = request.POST.get('name', '')
            mobile = request.POST.get('mobile', '')
            duty = request.POST.get('duty', '')
            channel = request.POST.get('channel', '')
            call_sign = request.POST.get('callSign', '')
            level = int(request.POST.get('level', 0))
            role = int(request.POST.get('role', 0))
            road_section_station = int(
                request.POST.get('road_section_station', 0))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)

        cur_faculty = Faculty.objects.get(id=faculty_id)
        cur_faculty.mobile = mobile
        cur_faculty.name = name
        cur_faculty.duty = duty
        cur_faculty.channel = channel
        cur_faculty.call_sign = call_sign
        if not is_already_in_use(faculty_id):
            cur_faculty.level = level
            cur_faculty.role = role
            cur_faculty.main_id = road_section_station

        # 岗位人数限制
        count = check_faculty_count_particular_role(cur_faculty)
        if count >= 4:
            return generate_error_response(
                error_constants.ERR_FACULTY_EXCEED_COUNT,
                status.HTTP_400_BAD_REQUEST)
        else:
            with transaction.atomic():
                cur_faculty.save()
        return Response(response_data, status=status.HTTP_200_OK)
Exemple #21
0
    def get(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            section_id = int(request.GET.get('sectionId', 0))
            district_id = int(request.GET.get('districtId', 0))
            station_id = int(request.GET.get('stationId', 0))
            filter_type = int(request.GET.get('filterType', 0))
            cur_per_page = int(request.GET.get('perPage', 20))
            page = int(request.GET.get('page', 1))
            section_name = ''
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)

        if station_id:
            cur_station = Station.objects.filter(enabled=1,
                                                 id=station_id).order_by('-id')
        elif section_id:
            section_name = Section.objects.get(id=section_id).name
            cur_station = Station.objects.filter(
                enabled=1, section_id=section_id).order_by('-id')
        else:
            cur_station = Station.objects.filter(enabled=1).order_by('-id')
            if district_id:
                cur_station = cur_station.filter(
                    district_id=district_id).order_by('-id')
            if filter_type == 1:
                cur_station = cur_station.filter(section_id__isnull=False)
            if filter_type == 2:
                cur_station = cur_station.exclude(section_id__isnull=False)
        paginator = Paginator(cur_station, cur_per_page)
        page_count = paginator.num_pages

        try:
            station_lists = paginator.page(page)
        except PageNotAnInteger:
            page = 1
            station_lists = paginator.page(page)
        except EmptyPage:
            page = paginator.num_pages
            station_lists = paginator.page(page)
        serializer = StationSerializer(station_lists, many=True)
        response_data['data'] = {}
        response_data['data']['sectionName'] = section_name
        response_data['data']['curPage'] = page
        response_data['data']['listCount'] = paginator.count
        response_data['data']['list'] = serializer.data
        response_data['data']['pageCount'] = page_count
        return Response(response_data, status.HTTP_200_OK)
Exemple #22
0
 def get(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1],
                      'data': {}}
     try:
         service_line_id = int(request.GET.get('serviceLineId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_service_line = ServiceLine.objects.get(id=service_line_id)
     response_data['data'] = ServiceLineExcelSerializer(cur_service_line).data
     return Response(response_data, status.HTTP_200_OK)
Exemple #23
0
 def get(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         section_id = int(request.GET.get('sectionId', 0))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_section = Section.objects.get(enabled=1, id=section_id)
     serializer = SectionSerializer(cur_section)
     response_data['data'] = serializer.data
     return Response(response_data, status.HTTP_200_OK)
Exemple #24
0
    def delete(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            faculty_id = int(request.GET.get('facultyId'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)

        try:
            Faculty.objects.filter(id=faculty_id).update(enabled=False)
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        return Response(response_data, status.HTTP_200_OK)
Exemple #25
0
 def delete(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         service_line_id = int(request.data.get('serviceLineId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_service_line = ServiceLine.objects.get(id=service_line_id)
     cur_service_line.enabled = False
     with transaction.atomic():
         cur_service_line.save()
     return Response(response_data, status.HTTP_200_OK)
Exemple #26
0
    def get(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1],
            'dataList': []
        }
        try:
            service_line_id = int(request.GET.get('serviceLineId'))
            district_id = int(request.GET.get('districtId'))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        # 当前勤务路线的地区id
        service_line_district_list = ServiceLine.objects.get(id=service_line_id).\
            district.all().values_list('id', flat=True)
        # 当前勤务路线的路线road
        service_line_road_list = ServiceLine.objects.get(id=service_line_id).\
            road.all().values_list('id', flat=True)

        query1 = Q()

        temp1 = Q()
        temp1.connector = 'AND'
        temp1.children.append(('enabled', True))
        if district_id:
            temp1.children.append(('district_id', district_id))
        query1.add(temp1, 'AND')

        temp2 = Q()
        temp2.connector = 'AND'
        temp2.children.append(('district_id__in', service_line_district_list))
        temp2.children.append(('Road_Service__isnull', True))
        query1.add(temp2, 'AND')

        # query2 = Q()
        # query2.connector = 'AND'
        # query2.children.append(('id__in', service_line_road_list))

        # road_list = Road.objects.filter(query1).exclude(query2).order_by('id')
        road_list = Road.objects.filter(query1).order_by('-id')
        serializer = RoadSerializer(road_list, many=True)
        response_data['dataList'] = serializer.data
        return Response(response_data, status.HTTP_200_OK)
Exemple #27
0
 def get(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
     }
     try:
         road_id = int(request.GET.get('roadId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     print(road_id)
     cur_road = Road.objects.get(id=road_id)
     serializer = SingleRoadSerializer(cur_road)
     response_data['data'] = serializer.data
     return Response(response_data, status.HTTP_200_OK)
Exemple #28
0
    def get(self, request):
        response_data = {
            'retCode': error_constants.ERR_STATUS_SUCCESS[0],
            'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
        }
        try:
            faculty_id = int(request.GET.get('facultyId', 0))
            district_id = int(request.GET.get('districtId', 0))
            cur_per_page = int(request.GET.get('perPage', 20))
            page = int(request.GET.get('page', 1))
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(
                error_constants.ERR_INVALID_PARAMETER,
                status.HTTP_400_BAD_REQUEST)
        if faculty_id:
            cur_faculty = Faculty.objects.get(id=faculty_id)
            serializer = FacultySerializer(cur_faculty)
            response_data['data'] = serializer.data
        else:
            cur_faculty = Faculty.objects.filter(enabled=True).order_by('-id')
            if district_id:
                cur_faculty = cur_faculty.filter(
                    district_id=district_id).order_by('-id')
            paginator = Paginator(cur_faculty, cur_per_page)
            page_count = paginator.num_pages

            try:
                faculty_lists = paginator.page(page)
            except PageNotAnInteger:
                page = 1
                faculty_lists = paginator.page(page)
            except EmptyPage:
                page = paginator.num_pages
                faculty_lists = paginator.page(page)
            serializer = FacultySerializer(faculty_lists, many=True)
            response_data['data'] = {}
            response_data['data']['curPage'] = page
            response_data['data']['listCount'] = paginator.count
            response_data['data']['list'] = serializer.data
            response_data['data']['pageCount'] = page_count
        return Response(response_data, status.HTTP_200_OK)
Exemple #29
0
 def get(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
     }
     for item in district:
         code = item.get('code')
         name = item.get('name')
         if not District.objects.filter(name=name, code=code).exists():
             cur_district = District(name=name, code=code)
             try:
                 with transaction.atomic():
                     cur_district.save()
             except Exception as ex:
                 print 'function name: ', __name__
                 print Exception, ":", ex
                 return generate_error_response(
                     error_constants.ERR_SAVE_INFO_FAIL,
                     status.HTTP_500_INTERNAL_SERVER_ERROR)
     return Response(response_data, status.HTTP_200_OK)
Exemple #30
0
 def post(self, request):
     response_data = {
         'retCode': error_constants.ERR_STATUS_SUCCESS[0],
         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]
     }
     try:
         service_line_id = int(request.POST.get('serviceLineId'))
         road_id = int(request.POST.get('roadId'))
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(
             error_constants.ERR_INVALID_PARAMETER,
             status.HTTP_400_BAD_REQUEST)
     cur_service_line = ServiceLine.objects.get(id=service_line_id)
     cur_road = Road.objects.get(id=road_id)
     cur_service_line.road.add(cur_road)
     # 更新serviceline的roadids
     update_service_line_road_ids(service_line_id, road_id, True)
     return Response(response_data, status.HTTP_200_OK)