Exemplo n.º 1
0
def before_request():
    request_infos = ''.join([
        request.method, 'path:', request.path, str(request_data())
    ])
    logger.info('request endpoint : %s' % (request.endpoint))
    logger.info('request url : %s' % (request.path))
    logger.info('request headers: %s' % (request.headers.items()))
    logger.info('request GET  data: %s' % (request.values.items()))
    logger.info('request POST data: %s' % (request.data))
    logger.info('\nrequest:{}'.format(request_infos))
    if request.path == '/':
        pass
    else:
        _in = False
        for item in FILTER_AUTH:
            if request.path.find(item) == 0:
                _in = True
                break
        if False == _in:
            token = unicode(request_data().get('token'))
            if not token:
                abort(400)
            rexpire(get_token(token), EXPIRE_TIME)
            user = hgetall(get_token(token))
            if not user:
                abort(401)
            if user and int(user['role_type']) not in cs.USER_ROLE_TYPE.keys():
                abort(403)
Exemplo n.º 2
0
def get_location_info(token, location_code):
    """
    获取转运网点信息
    :param token:
    :param location_code:
    :return:
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None
    location = Location.query.filter_by(location_code=location_code).first()
    location_obj = {}
    if location:
        location_obj['location_code'] = location.location_code
        location_obj['location_name'] = location.location_name
        location_obj['detailed_address'] = location.detailed_address
        location_obj['lot'] = location.lot
        location_obj['lat'] = location.lat
        location_obj['province'] = location.province
        location_obj['city'] = location.city
        location_obj['location_status'] = location.location_status
        location_obj['create_time'] = location.create_time
        location_obj['location_contacts'] = get_location_contacts(
            location.location_code)

    return cs.OK, {'location_objs': location_obj}
Exemplo n.º 3
0
def modify_location_info(token, location_code, location_name, detailed_address,
                         lot, lat):
    """
    修改转运中心信息
    :param token:
    :param location_name:
    :param detailed_address:
    :param lot:
    :param lat:
    :return:cs.OK, location_code
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None
    try:
        location_obj = Location.query.filter_by(
            location_code=location_code).first()
        if location_obj:
            location_obj.location_name = location_name
            location_obj.detailed_address = detailed_address
            location_obj.lot = lot
            location_obj.lat = lat
            location_obj.update_time = datetime.now()
            db.session.commit()
            return cs.OK, location_code
        else:
            return cs.LOCATION_CODE_ERR, None
    except:
        logger.error("modify location err : {}".format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 4
0
def get_line(token, line_code):
    """
    获取线路信息
    :param token:
    :param line_code:
    :return:
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) not in cs.SELECT_LINE_ROLE:
        return cs.AUTH_ERROR, None
    line_obj = Line.query.filter_by(line_code=line_code).first()
    if not line_obj:
        return cs.LINE_CODE_ERR, {'line_code': line_code}
    line = {}
    line['line_code'] = line_obj.line_code
    line['line_name'] = line_obj.line_name
    line['origin_name'] = get_location(line_obj.origin_code).location_name
    line['destination_name'] = get_location(
        line_obj.destination_code).location_name
    line['line_status'] = line_obj.line_status
    line['line_type'] = line_obj.line_type
    line['line_kilometre'] = line_obj.line_kilometre
    line['line_runtime'] = line_obj.line_runtime
    line['location_number'] = line_obj.location_number
    line['location_infos'] = []
    # 获取径停点信息
    location_objs = LineLocations.query.filter_by(fk_line_code=line_code).all()
    if location_objs:
        for item in location_objs:
            location_name = get_location(item.location_code).location_name
            line['location_infos'].append({
                'location_name': location_name,
                'sequence': item.sequence
            })
    return cs.OK, line
Exemplo n.º 5
0
def enabled_disable_location(token, location_code, location_status):
    """
    启用禁用转运中心
    :param token:
    :param location_code:
    :param location_status:
    :return: cs.OK
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None
        # location_stauts 验证在route中
    # if location_status not in cs.LOCATION_STATUS_INDEX.keys():
    #     return cs.PARAMS_ERROR, {"look": 'look'}

    # 修改数据
    try:
        location_obj = Location.query.filter_by(
            location_code=location_code).first()
        if location_obj:
            location_obj.location_status = location_status
            db.session.commit()
            return cs.OK, location_code
        else:
            return cs.LOCATION_CODE_ERR, None
    except:
        logger.error("modify location err : {}".format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 6
0
def get_truck_info(token, plate):
    """
    车辆信息查询
    :param token:
    :param plate:
    :return:cs.OK, object
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None

    truck_obj = Truck.query.filter_by(plate=plate).first()
    if truck_obj:
        truck = {}
        truck['plate'] = truck_obj.plate
        truck['container_type'] = truck_obj.container_type
        truck['plate_type'] = truck_obj.plate_type
        truck['vehicle_type'] = truck_obj.vehicle_type
        truck['container_length'] = truck_obj.container_length
        truck['container_wide'] = truck_obj.container_wide
        truck['container_high'] = truck_obj.container_high
        truck['container_volume'] = truck_obj.container_volume
        truck['status'] = truck_obj.status
        return cs.OK, truck
    else:
        return cs.PLATE_ERR, {'plate': plate}
Exemplo n.º 7
0
def enabled_disable_truck(token, plate, status):
    """
    启用禁用车辆
    :param token:
    :param plate:
    :param status:
    :return: cs.OK, dict
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
        return cs.AUTH_ERROR, None
    try:
        truck_obj = Truck.query.filter_by(plate=plate).first()
        if truck_obj:
            truck_obj.status = status
            truck_obj.update_time = datetime.datetime.now()
            db.session.commit()
            return cs.OK, {'plate': plate}
        else:
            return cs.PLATE_ERR, {'plate': plate}
    except:
        logger.error("modify line err : {}".format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 8
0
def modify_location(token, location_list):
    """
    修改转运中心联系人
    :param token:
    :param location_list:
    :return: cs.OK, None
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None

    if location_list:
        try:
            for location in location_list:
                location_obj = LC.query.filter_by(
                    fk_location_code=location['location_code'],
                    contacts_name='').first()
                if location_obj:
                    location_obj.contacts_name = location['contacts_name']
                    location_obj.contacts_telephone = location[
                        'contacts_telephone']
            db.session.commit()
            return cs.OK, None
        except:
            logger.error("modify location err : {}".format(
                traceback.format_exc(), ))
            raise
        finally:
            db.session.rollback()
Exemplo n.º 9
0
def modify_waybill_type(token, waybill_number, waybill_type, remarks):
    """
    修改运单属性
    :param token:
    :param waybill_numberm:
    :param waybill_type: 运单类型: 1:正常, 2:异常, 3:废止
    :return: 1000, 运单号
    """
    try:
        user = hgetall(get_token(token))
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
            return cs.AUTH_ERROR, None
        # 验证运单
        waybill_obj = Waybill.query.filter_by(
            waybill_number=waybill_number).first()
        if not waybill_obj:
            return cs.WAYBILL_NUMBER_ERR, {
                "err_waybill_number": waybill_number
            }
        # 修改关联货物订单类型,同时增加备注
        # 根据运单号查询对应的货物订单
        if waybill_obj.waybill_status == cs.WAYBILL_STATUS_INFO[u"待装车"]:
            if waybill_type == cs.WAYBILL_TYPE_INFO[u'废止']:
                # 修改运单属性
                waybill_obj.waybill_type = waybill_type
                waybill_obj.remarks = remarks
                # 释放订单
                cargo_order_objs = CargoOrder.query.filter_by(
                    fk_waybill_number=waybill_number).all()
                if cargo_order_objs:
                    for cargo_order_obj in cargo_order_objs:
                        cargo_order_obj.order_status = cs.CARGO_ORDER_STATUS_INFO[
                            u"待接单"]
                        cargo_order_obj.fk_waybill_number = None
            else:
                waybill_obj.waybill_type = waybill_type
                waybill_obj.remarks = remarks

        elif waybill_obj.waybill_status == cs.WAYBILL_STATUS_INFO[u"运输中"]:
            # 修改运单属性
            waybill_obj.waybill_type = waybill_type
            waybill_obj.remarks = remarks
            # 修改订单属性
            cargo_order_objs = CargoOrder.query.filter_by(
                fk_waybill_number=waybill_number).all()
            if cargo_order_objs:
                for cargo_order_obj in cargo_order_objs:
                    cargo_order_obj.order_status = cs.WAYBILL_TYPE_ORDER_STATUS[
                        waybill_type]
                    if waybill_type == cs.WAYBILL_TYPE_INFO[u"废止"]:
                        cargo_order_obj.fk_waybill_number = None
        db.session.commit()
        return cs.OK, {'waybill_number': waybill_number}
    except:
        logger.error('create_waybill err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 10
0
def cargo_choose_line(token, cargo_order_number, line_code):
    """
    货物订单选择线路
    :param token:
    :param cargo_order_number:  货物订单号
    :param line_code:   线路编号
    :return: cs.OK
    """
    try:
        user = hgetall(get_token(token))
        # 验证用户权限
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"货物订单统筹专员"]:
            return cs.AUTH_ERROR, None
        # 验证货物订单
        cargo_order_obj = CargoOrder.query.filter_by(
            cargo_order_number=cargo_order_number).first()
        if not cargo_order_obj:
            return cs.NOT_CARGO_ORDER, None
        if cargo_order_obj.order_status != cs.CARGO_ORDER_STATUS_INFO[u"待接单"]:
            return cs.CARGO_ORDER_STATUS_ABNORMAL, None
        # 验证线路
        line_obj = Line.query.filter_by(line_code=line_code).first()
        if not line_obj:
            return cs.LINE_CODE_ERR, None
        if line_obj.line_status != cs.LINE_STATUS_INFO[u"启用"]:
            return cs.LINE_STATUS_ERR, None

        # 验证线路是否在推荐的线路集合内
        push_line_list = rget(push_line(cargo_order_number))
        if push_line_list:
            push_line_list = json.loads(push_line_list)
        else:
            push_line_list = []

        if line_code not in push_line_list:
            return cs.LINE_PUSH_ERR, {'line_code': line_code}
        # 插入线路编号
        cargo_order_obj.fk_line_code = line_code
        db.session.commit()
        # insert line_volume
        code = line_volume_set(line_code, cargo_order_obj.cargo_volume,
                               cargo_order_obj.cargo_weight, user['id'])
        if code is not cs.OK:
            logger.error(
                'insert line volume err line_name:{}, cargo_order_number:{}'.
                format(line_code, cargo_order_number))
        # 清空key
        delete(push_line(cargo_order_number))
        return cs.OK, {'cargo_order_number': cargo_order_number}
    except:
        logger.error('cargo_choose_line err {}'.format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 11
0
def get_cargo_order(token, cargo_order_number):
    """
    查看货物订单详情

    :param token:
    :param cargo_order_number:
    :return: cs.OK, object
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None

    # 货物订单信息
    cargo_order_obj = CargoOrder.query.filter_by(
        cargo_order_number=cargo_order_number).first()
    if not cargo_order_obj:
        return cs.NOT_CARGO_ORDER, None
    cargo_order = {}
    cargo_order['cargo_order_number'] = cargo_order_obj.cargo_order_number
    cargo_order['origin_name'] = get_location(
        cargo_order_obj.origin_code).location_name
    cargo_order['destination_name'] = get_location(
        cargo_order_obj.destination_code).location_name
    cargo_order['order_status'] = cargo_order_obj.order_status
    cargo_order['order_type'] = cargo_order_obj.order_type
    cargo_order['cargo_name'] = cargo_order_obj.cargo_name
    cargo_order['cargo_volume'] = cargo_order_obj.cargo_volume
    cargo_order['cargo_weight'] = cargo_order_obj.cargo_weight
    cargo_order[
        'specified_arrival_time'] = cargo_order_obj.specified_arrival_time
    cargo_order['consignor_name'] = cargo_order_obj.consignor_name
    cargo_order['consignor_telephone'] = cargo_order_obj.consignor_telephone
    cargo_order['consignee_name'] = cargo_order_obj.consignee_name
    cargo_order['consignee_telephone'] = cargo_order_obj.consignee_telephone
    cargo_order['create_time'] = cargo_order_obj.create_time
    # 货物订单流
    cargo_order['order_flows'] = get_order_flows(cargo_order_number)
    # 货物订单操作日志
    cargo_order['order_operations'] = get_operation_records(cargo_order_number)
    # 推送线路信息
    line_nos = json.loads(rget(push_line(cargo_order_number)))
    line_list = []
    for line_no in line_nos:
        line_obj = Line.query.filter_by(
            line_code=line_no, line_status=cs.LINE_STATUS_INFO[u"启用"]).first()
        line_dict = {}
        if line_obj:
            line_dict['line_code'] = line_obj.line_code
            line_dict['line_name'] = line_obj.line_name
            line_dict['line_kilometre'] = line_obj.line_kilometre
            line_dict['line_runtime'] = line_obj.line_runtime
            line_list.append(line_dict)
    cargo_order['push_lines'] = line_list
    # cargo_order['push_lines'] = rget(push_line(cargo_order_number))
    return cs.OK, cargo_order
Exemplo n.º 12
0
def modify_waybill_status(token, waybill_number, waybill_status):
    """
    修改运单状态
    :param token:
    :param waybill_number: 运单号
    :param waybill_status: 运单状态 200:待装车, 300:运输中 , 500:已完成
    :return:1000, 运单号
    """
    try:
        user = hgetall(get_token(token))
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
            return cs.AUTH_ERROR, None
        # user['fk_location_code'] = int(user['fk_location_code'])
        # 验证运单
        waybill_obj = Waybill.query.filter_by(
            waybill_number=waybill_number).first()
        if not waybill_obj:
            return cs.WAYBILL_NUMBER_ERR, {
                "err_waybill_number": waybill_number
            }
        # 对运单状态进行验证
        if waybill_status != cs.WAYBILL_STATUS_CHANGE[
                waybill_obj.waybill_status]:
            return cs.WAYBILL_STATUS_ERR, {
                'err_waybill_number': waybill_number
            }
        # 验证运单修改状态与用户权限是否匹配
        if waybill_status == cs.WAYBILL_STATUS_INFO[u"运输中"]:
            if user['fk_location_code'] != waybill_obj.fk_to_location_code:
                return cs.AUTH_ERROR, None
        if waybill_status == cs.WAYBILL_STATUS_INFO[u"已完成"]:
            if user['fk_location_code'] != waybill_obj.fk_at_location_code:
                return cs.AUTH_ERROR, None

        waybill_obj.waybill_status = waybill_status
        # 修改关联货物订单状态
        # 根据运单号查询对应的货物订单
        cargo_order_objs = CargoOrder.query.filter_by(
            fk_waybill_number=waybill_number).all()
        if cargo_order_objs:
            for cargo_order_obj in cargo_order_objs:
                cargo_order_obj.order_status = cs.WAYBILL_CARGO_STATUS_CHANGE[
                    waybill_status]

        db.session.commit()
        return cs.OK, {'waybill_number': waybill_number}
    except:
        logger.error('create_waybill err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 13
0
def get_line_locations(token, origin_code, destination_code, location_code,
                       location_status, page_index, page_size):
    """
    获取转运中心列表
    :param token:
    :param origin_code:
    :param destination_code:
    :param location_code:
    :param location_status:
    :param page_index:
    :param page_size:
    :return: cs.OK,{}
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) not in cs.SELECT_LINE_ROLE:
        return cs.AUTH_ERROR, None

    statment = '1=1'
    if origin_code:
        statment += " and (line_location.origin_code = '%s')" % origin_code

    if destination_code:
        statment += " and (line_location.destination_code = '%s')" % destination_code

    if location_code:
        statment += " and (line_location.location_code = '%s')" % location_code

    if location_status:
        statment += " and (line_location.location_status = '%s')" % location_status
    else:
        statment += " and (line_location.location_status = '%s')" % cs.LINE_STATUS_INFO[
            u"启用"]

    print statment
    line_locations = LineLocations.query.filter(statment).order_by(
        LineLocations.update_time.desc()).paginate(page_index, page_size,
                                                   False).items
    lines_count = db.session.query(LineLocations.id).filter(statment).count()
    rasult = {'line_objs': [], 'line_count': lines_count}
    for item in line_locations:
        line = {}
        line_obj = Line.query.filter_by(line_code=item.fk_line_code).first()
        line['line_code'] = line_obj.line_code
        line['line_name'] = line_obj.line_name
        line['origin_name'] = get_location(line_obj.origin_code).location_name
        line['destination_code'] = get_location(
            line_obj.destination_code).location_name
        line['line_kilometre'] = line_obj.line_kilometre
        line['line_runtime'] = line_obj.line_runtime
        line['location_number'] = line_obj.location_number
        rasult['line_objs'].append(line)
    return cs.OK, rasult
Exemplo n.º 14
0
def get_lines(token, line_code, origin_code, destination_code, line_status,
              line_type, page_index, page_size):
    """
    货物线路列表
    :param token:
    :param line_code:
    :param origin_code:
    :param destination_code:
    :param line_status:
    :param line_type:
    :param page_index:
    :param page_size:
    :return: cs.OK,{}
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) not in cs.SELECT_LINE_ROLE:
        return cs.AUTH_ERROR, None
    statment = '1=1'

    if line_code:
        statment += " and (line.line_code = '%s')" % line_code
    if origin_code:
        statment += " and (line.origin_code = '%s')" % origin_code
    if destination_code:
        statment += " and (line.destination_code = '%s')" % destination_code
    if line_type:
        statment += " and (line.line_type = '%s')" % line_type
    if line_status:
        statment += " and (line.line_status = '%s')" % line_status
    else:
        statment += " and (line.line_status = '%s')" % cs.LINE_STATUS_INFO[
            u"启用"]

    lines_objs = Line.query.filter(statment).order_by(
        Line.update_time.desc()).paginate(page_index, page_size, False).items
    logger.info('get_lines statment is {}'.format(statment, ))
    lines_count = db.session.query(Line.id).filter(statment).count()
    rasult = {'line_objs': [], 'line_count': lines_count}
    for item in lines_objs:
        line = {}
        line['line_code'] = item.line_code
        line['line_name'] = item.line_name
        line['origin_name'] = get_location(item.origin_code).location_name
        line['destination_code'] = get_location(
            item.destination_code).location_name
        line['line_kilometre'] = item.line_kilometre
        line['line_runtime'] = item.line_runtime
        line['location_number'] = item.location_number
        rasult['line_objs'].append(line)
    return cs.OK, rasult
Exemplo n.º 15
0
def get_line_names(token, chars):
    """
    线路模糊查询
    :param token:
    :param chars:
    :return:
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None
    lines = db.session.query(Line.line_code, Line.line_name).distinct().filter(
        Line.line_name.like('%' + str(chars) + '%')).all()
    line_list = []
    for line in lines:
        line_list.append({'line_code': line.line_code, 'name': line.line_name})
    return cs.OK, line_list
Exemplo n.º 16
0
def get_truck_plates(token, chars):
    """
    线路模糊查询
    :param token:
    :param chars:
    :return:cs.OK, list
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None
    trucks = db.session.query(Truck.plate).distinct().filter(
        Truck.plate.like('%' + str(chars) + '%')).all()
    truck_list = []
    for truck in trucks:
        truck_list.append({'plate': truck.plate})
    return cs.OK, truck_list
Exemplo n.º 17
0
def get_truck_infos(token, plate, status, plate_type, vehicle_type,
                    container_type, page_index, page_size):
    """
    车辆列表查询
    :param token:
    :param plate:
    :param status:
    :param plate_type:
    :param vehicle_type:
    :param container_type:
    :param page_index:
    :param page_size:
    :return:cs.OK, dict
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None
    statment = '1=1'

    if plate:
        statment += " and (truck.plate = '%s')" % plate
    if status:
        statment += " and (truck.status = '%s')" % status
    else:
        statment += " and (truck.status = '%s')" % cs.TRUCK_STATUS_INFO[u"启用"]
    if plate_type:
        statment += " and (truck.plate_type = '%s')" % plate_type
    if vehicle_type:
        statment += " and (truck.vehicle_type = '%s')" % vehicle_type
    if container_type:
        statment += " and (truck.container_type = '%s')" % container_type

    truck_objs = Truck.query.filter(statment).order_by(
        Truck.update_time.desc()).paginate(page_index, page_size, False).items
    logger.info('get_trucks statment is {}'.format(statment, ))
    truck_count = db.session.query(Truck.id).filter(statment).count()
    rasult = {'truck_objs': [], 'truck_count': truck_count}
    for item in truck_objs:
        truck = {}
        truck['plate'] = item.plate
        truck['status'] = item.status
        truck['plate_type'] = item.plate_type
        truck['vehicle_type'] = item.vehicle_type
        truck['container_type'] = item.container_type
        truck['container_volume'] = item.container_volume
        rasult['truck_objs'].append(truck)
    return cs.OK, rasult
Exemplo n.º 18
0
def get_location_infos(token, location_code, province, city, location_status,
                       page_index, page_size):
    """
    转运网点列表
    :param token:
    :param location_code:
    :param province:
    :param city:
    :param location_status:
    :return:
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None
    statment = '1=1'

    if location_code:
        statment += " and (location.location_code = '%s')" % location_code
    if province:
        statment += " and (location.province = '%s')" % province
    if city:
        statment += " and (location.city = '%s')" % city
    if location_status:
        statment += " and (location.location_status = '%s')" % location_status
    else:
        statment += " and (location.location_status = '%s')" % cs.LOCATION_STATUS_INFO[
            u"启用"]

    location_objs = Location.query.filter(statment).order_by(
        Location.update_time.desc()).paginate(page_index, page_size,
                                              False).items
    # location_objs = Location.query.filter(statment).order_by(Location.update_time.desc())
    logger.info('get_lines statment is {}'.format(statment, ))
    locations_count = db.session.query(Location.id).filter(statment).count()
    rasult = {'location_objs': [], 'location_count': locations_count}
    for item in location_objs:
        location = {}
        location['location_code'] = item.location_code
        location['location_name'] = item.location_name
        location['province'] = item.province
        location['city'] = item.city
        location['location_status'] = item.location_status
        rasult['location_objs'].append(location)
        print item.location_code

    return cs.OK, rasult
Exemplo n.º 19
0
def modify_line(token, line_code, line_status, line_type):
    """
    修改线路属性和状态
    :param token:
    :param line_code:
    :param line_status:
    :param line_type:
    :return: cs.OK,{}
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None
    try:
        # 验证线路编码
        line = Line.query.filter_by(line_code=line_code).first()
        if not line:
            return cs.LINE_CODE_ERR, {'line_code': line_code}
        if line_status:
            line_status = int(line_status)
            if line_status in cs.LINE_STATUS_INDEX.keys():
                line.line_status = line_status
                # 径停点同步改变
                line_locations = LineLocations.query.filter_by(
                    fk_line_code=line_code).all()
                for item in line_locations:
                    item.location_status = line_status
            else:
                return cs.LINE_STATUS_ERR, None

        if line_type:
            line_type = int(line_type)
            if line_type in cs.LINE_TYPE_INDEX.keys():
                line.line_type = line_type
            else:
                return cs.LINE_TYPE_ERR, None
        db.session.commit()
        return cs.OK, {'line_code': line_code}
    except:
        logger.error("modify line err : {}".format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 20
0
def get_location_names(token, chars):
    """
    转运网点模糊查询
    :param chars:
    :return:cs.OK, list
    """
    user = hgetall(get_token(token))
    if not user:
        return cs.AUTH_ERROR, None
    locations = db.session.query(
        Location.location_code, Location.location_name).distinct().filter(
            Location.location_name.like('%' + str(chars) + '%'),
            Location.location_status == cs.LOCATION_STATUS_INFO[u"启用"]).all()
    locations_list = []
    for location in locations:
        locations_list.append({
            'code': location.location_code,
            'name': location.location_name
        })
    return cs.OK, locations_list
Exemplo n.º 21
0
def modify_truck(token, plate, container_type, plate_type, vehicle_type,
                 container_length, container_wide, container_high,
                 container_volume, status):
    """
    修改车辆信息
    :param token:
    :param plate:
    :param container_type:
    :param plate_type:
    :param vehicle_type:
    :param container_length:
    :param container_wide:
    :param container_high:
    :param container_volume:
    :param status:
    :return: cs.OK,dict
    """
    try:
        user = hgetall(get_token(token))
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
            return cs.AUTH_ERROR, None
        truck_obj = Truck.query.filter_by(plate=plate).first()
        if not truck_obj:
            return cs.PLATE_ERR, {'plate': plate}
        truck_obj.container_type = container_type
        truck_obj.plate_type = plate_type
        truck_obj.vehicle_type = vehicle_type
        truck_obj.container_length = container_length
        truck_obj.container_wide = container_wide
        truck_obj.container_high = container_high
        truck_obj.container_volume = container_volume
        truck_obj.status = status
        truck_obj.update_time = datetime.datetime.now()
        db.session.commit()
        return cs.OK, {'plate': plate}
    except:
        logger.error('modify truck err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 22
0
def create_truck(token, plate, status, plate_type, vehicle_type,
                 container_type, container_length, container_wide,
                 container_high, container_volume):
    """
    新增车辆
    :param token:
    :param plate:
    :param status:
    :param plate_type:
    :param vehicle_type:
    :param container_type:
    :param container_length:
    :param container_wide:
    :param container_high:
    :param container_volume:
    :return:cs.OK, dict
    """
    try:
        user = hgetall(get_token(token))
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
            return cs.AUTH_ERROR, None
        # 验证车牌
        truck_obj = Truck.query.filter_by(plate=plate).first()
        if truck_obj:
            return cs.PLATE_EXIST, {'plate': plate}

        truck = Truck(plate, status, plate_type, vehicle_type, container_type,
                      container_length, container_wide, container_high,
                      container_volume, user['id'])
        db.session.add(truck)
        db.session.commit()
        return cs.OK, {'plate': plate}
    except:
        logger.error('create truck err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 23
0
def create_location(token, location_name, detailed_address, lot, lat, province,
                    city, location_contactss):
    """
    创建转运网点
    :param token:
    :param location_name:
    :param detailed_address:
    :param lot:
    :param lat:
    :param province:
    :param city:
    :return:
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None
    # 生成location_code
    location_code = generate_location_code()
    try:
        location_obj = Location(location_name, location_code, detailed_address,
                                lot, lat, province, city,
                                cs.LOCATION_STATUS_INFO[u"启用"])
        # 创建网点联系人
        if location_contactss:
            print location_contactss
            for item in location_contactss:
                location_contacts = LC(location_code, item['contacts_name'],
                                       item['contacts_telephone'])
                db.session.add(location_contacts)
        db.session.add(location_obj)
        db.session.commit()
        return cs.OK, location_code
    except:
        logger.error("create location err : {}".format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 24
0
def enabled_disable_line(token, line_code, line_status):
    """
    启用禁用线路
    :param token:
    :param line_code:
    :param line_status:
    :return: cs.OK,{}
    """
    user = hgetall(get_token(token))
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"线路规划专员"]:
        return cs.AUTH_ERROR, None
    try:
        line_obj = Line.query.filter_by(line_code=line_code).first()
        if line_obj:
            line_obj.line_status = line_status
            db.session.commit()
            return cs.OK, {'line_code': line_code}
        else:
            return cs.LOCATION_CODE_ERR, {'line_code': line_code}
    except:
        logger.error("modify line err : {}".format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 25
0
def get_cargo_orders(token, start_date, end_date, order_status,
                     cargo_order_number, origin_code, destination_code,
                     page_index, page_size, select_flag):
    """
    获取货物订单列表
    :param token:
    :param start_date:
    :param end_date:
    :param order_status:
    :param cargo_order_number:
    :param origin_code:
    :param destination_code:
    :param page_index:
    :param page_size:
    :param select_flag:
    :return: cs.OK, {}
    """
    user = hgetall(get_token(token))
    user_role_type = int(user['role_type'])
    # 验证用户权限
    if (not user) or int(user['role_type']) not in [
            cs.USER_ROLE_INFO[u"商家"], cs.USER_ROLE_INFO[u"货物订单统筹专员"]
    ]:
        return cs.AUTH_ERROR, None

    statment = '1=1'

    if True != cs.is_date(start_date) or True != cs.is_date(end_date):
        return cs.PARAMS_ERROR, {
            'start_date': start_date,
            'end_date': end_date
        }
    else:
        start_date = datetime.strptime(str(start_date), "%Y-%m-%d").date()
        end_date = datetime.strptime(str(end_date), "%Y-%m-%d").date()
        date_interval = (end_date - start_date).days
        if date_interval > 90:
            return cs.DATE_INTERVAL_TOO_LONG, {'date_interval': date_interval}

        statment += " and (cargo_order.create_date between '%s' and '%s')" % (
            start_date, end_date)

    if cargo_order_number:
        statment = "1=1 and (cargo_order.cargo_order_number = '%s')" % cargo_order_number
    if order_status:
        statment += " and (cargo_order.order_status = '%s')" % order_status
    if user_role_type == cs.USER_ROLE_INFO[u"商家"]:
        statment += " and (cargo_order.fk_operator_id = '%s')" % user['id']
        if destination_code:
            statment += " and (cargo_order.destination_code = '%s')" % destination_code
        if origin_code:
            statment += " and (cargo_order.origin_code = '%s')" % origin_code

    if user_role_type == cs.USER_ROLE_INFO[u"货物订单统筹专员"]:
        if int(select_flag) == cs.SELECT_FLAG_INFO[u"查询始发地订单"]:
            statment += " and (cargo_order.origin_code = '%s')" % user[
                'fk_location_code']
            if destination_code:
                statment += " and (cargo_order.destination_code = '%s')" % destination_code

        if int(select_flag) == cs.SELECT_FLAG_INFO[u"查询目的地订单"]:
            statment += " and (cargo_order.destination_code = '%s')" % user[
                'fk_location_code']
            if origin_code:
                statment += " and (cargo_order.origin_code = '%s')" % origin_code

    cargo_orders = []
    cargo_orders_count = 0
    cargo_orders_objs = CargoOrder.query.filter(statment).order_by(
        CargoOrder.update_time.desc()).paginate(int(page_index),
                                                int(page_size), False)
    logger.info('get_cargo_orders statment is {}'.format(statment, ))
    cargo_orders_count = db.session.query(
        CargoOrder.id).filter(statment).count()

    for item in cargo_orders_objs.items:
        cargo_order = {}
        cargo_order['update_time'] = item.update_time
        cargo_order['create_date'] = item.create_date
        cargo_order['order_number'] = item.cargo_order_number
        cargo_order['order_status'] = item.order_status
        cargo_order['cargo_name'] = item.cargo_name
        cargo_order['origin_name'] = get_location(
            item.origin_code).location_name
        cargo_order['destination_code'] = get_location(
            item.destination_code).location_name
        cargo_orders.append(cargo_order)
    return cs.OK, {
        'cargo_orders': cargo_orders,
        'orders_count': cargo_orders_count
    }
Exemplo n.º 26
0
def modify_waybill(token, waybill_number, plate, driver_name, driver_telephone,
                   start_time, end_time, cargo_order_numbers, remarks):
    """
    修改运单数据
    :param token:
    :param waybill_number: 运单号
    :param plate: 车牌
    :param driver_name: 司机姓名
    :param driver_telephone: 司机号码
    :param start_time: 发车时间
    :param end_time: 到车时间
    :param cargo_order_numbers: 订单号集合
    :param remarks: 备注
    :return: 1000, 运单号
    """
    try:
        user = hgetall(get_token(token))
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
            return cs.AUTH_ERROR, None
        # 验证运单
        waybill_obj = Waybill.query.filter_by(
            waybill_number=waybill_number).first()
        if not waybill_obj:
            return cs.WAYBILL_NUMBER_ERR, {
                "err_waybill_number": waybill_number
            }
        if waybill_obj.waybill_status != cs.WAYBILL_STATUS_INFO[u"待装车"]:
            return cs.WAYBILL_STATUS_ERR, {
                "err_waybill_number": waybill_number
            }

        # 验证车牌
        truck_obj = Truck.query.filter_by(plate=plate).first()
        if not truck_obj:
            return cs.PLATE_ERR, None
        # 修改运单数据
        waybill_obj.plate = plate
        waybill_obj.driver_name = driver_name
        waybill_obj.driver_telephone = driver_telephone
        waybill_obj.start_time = start_time
        waybill_obj.end_time = end_time

        # 释放绑定的货物订单
        cargo_order_objs = CargoOrder.query.filter_by(
            fk_waybill_number=waybill_number).all()
        if cargo_order_objs:
            for cargo_order_obj in cargo_order_objs:
                cargo_order_obj.order_status = cs.CARGO_ORDER_STATUS_INFO[
                    u"待接单"]
                cargo_order_obj.fk_waybill_number = None
        # 重新绑定货物订单
        if cargo_order_numbers:
            for cargo_order_number in cargo_order_numbers:
                cargo_order_obj = CargoOrder.query.filter_by(
                    cargo_order_number=cargo_order_number).first()
                if not cargo_order_obj:
                    return cs.NOT_CARGO_ORDER, {
                        'err_cargo_order_number': cargo_order_number
                    }
                if cargo_order_obj.order_status != cs.CARGO_ORDER_STATUS_INFO[
                        u"待接单"]:
                    return cs.CARGO_ORDER_STATUS_ABNORMAL, {
                        'err_cargo_order_number': cargo_order_number
                    }
                # 更新货物订单
                cargo_order_obj.order_status = cs.CARGO_ORDER_STATUS_INFO[
                    u"已接单"]
                cargo_order_obj.fk_waybill_number = waybill_number
        db.session.commit()
        return cs.OK, {'waybill_number': waybill_number}
    except:
        logger.error('create_waybill err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 27
0
def web_logout():
    logger.debug('/order/auth/logout request data: {}'.format(request.values.items()))
    token = unicode(request_data().get('token'))
    delete(get_token(token))
    return rw(cs.OK, {})
Exemplo n.º 28
0
def create_waybill(token, line_code, start_time, end_time, plate, driver_name,
                   driver_telephone, remarks, cargo_order_numbers):
    """
    创建运单
    :param token:
    :param line_code:  线路编号
    :param start_time:  发车时间
    :param end_time:  到车时间
    :param plate:  车牌
    :param driver_name:  司机姓名
    :param driver_telephone:  司机号码
    :param remarks:  备注
    :param cargo_order_numbers:  货物订单号集合
    :return: 1000, 运单号
    """
    try:
        user = hgetall(get_token(token))
        if (not user) or int(
                user['role_type']) != cs.USER_ROLE_INFO[u"运单统筹专员"]:
            return cs.AUTH_ERROR, None
        # 验证线路
        line_obj = Line.query.filter_by(line_code=line_code).first()
        if not line_obj:
            return cs.LINE_CODE_ERR, None
        # 验证车牌
        truck_obj = Truck.query.filter_by(plate=plate).first()
        if not truck_obj:
            return cs.PLATE_ERR, None

        # 生成运单号
        waybill_number = 'W' + generate_order_number(date.today(),
                                                     cs.ORDER_INFO[u"运输订单"])
        # 获取始发地编码
        fk_to_location_code = line_obj.origin_code
        # 获取目的地编码
        fk_at_location_code = line_obj.destination_code
        # 初始化运单
        waybill = Waybill(waybill_number, cs.WAYBILL_TYPE_INFO[u"正常"],
                          cs.WAYBILL_STATUS_INFO[u"待装车"], line_code,
                          fk_to_location_code, fk_at_location_code, plate,
                          start_time, end_time, driver_name, driver_telephone,
                          remarks, user['id'], date.today())

        if cargo_order_numbers:
            cargos_volume = 0
            cargos_weight = 0
            for cargo_order_number in cargo_order_numbers:
                cargo_order_obj = CargoOrder.query.filter_by(
                    cargo_order_number=cargo_order_number).first()
                if not cargo_order_obj:
                    return cs.NOT_CARGO_ORDER, {
                        'err_cargo_order_number': cargo_order_number
                    }
                if cargo_order_obj.order_status != cs.CARGO_ORDER_STATUS_INFO[
                        u"待接单"]:
                    print cargo_order_obj.order_status
                    print cs.CARGO_ORDER_STATUS_INFO[u"待接单"]
                    return cs.CARGO_ORDER_STATUS_ABNORMAL, {
                        'err_cargo_order_number': cargo_order_number
                    }

                # 更新货物订单
                cargo_order_obj.order_status = cs.CARGO_ORDER_STATUS_INFO[
                    u"已接单"]
                cargo_order_obj.fk_waybill_number = waybill_number
                # 统计
                cargos_volume += cargo_order_obj.cargo_volume
                cargos_weight += cargo_order_obj.cargo_weight
            # 修改line_volume
            err, result = line_volume_get(line_code, cargos_volume,
                                          cargos_weight, user['id'])
            if err:
                return err, result

        db.session.add(waybill)
        db.session.commit()
        return cs.OK, {'waybill_number': waybill_number}
    except:
        logger.error('create_waybill err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 29
0
def create_cargo_order(token, origin_code, destination_code, cargo_name,
                       cargo_volume, cargo_weight, specified_arrival_time,
                       consignor_name, consignor_telephone, consignee_name,
                       consignee_telephone):
    """
    创建货物订单
    :param token:
    :param origin_code:
    :param destination_code:
    :param cargo_name:
    :param cargo_volume:
    :param cargo_weight:
    :param specified_arrival_time:
    :param consignor_name:
    :param consignor_telephone:
    :param consignee_name:
    :param consignee_telephone:
    :return: cs.OK, cargo_order_number
    """
    user = hgetall(get_token(token))
    # 验证用户权限
    if (not user) or int(user['role_type']) != cs.USER_ROLE_INFO[u"货物订单统筹专员"]:
        return cs.AUTH_ERROR, None
    # 验证转运网点
    origin_location = get_location(origin_code)
    destination_location = get_location(destination_code)
    if not origin_location and not destination_location:
        return cs.LOCATION_ERR, None
    if not (origin_location and destination_location):
        return cs.LOCATION_ERR, None
    # 获取货物订单号
    cargo_order_number = 'C' + generate_order_number(date.today(),
                                                     cs.ORDER_INFO[u"货物订单"])
    now_time = datetime.now()
    order_status = cs.CARGO_ORDER_STATUS_INFO[u"待接单"]
    order_type = cs.ORDER_INFO[u"货物订单"]
    fk_operator_id = user['id']
    remark = None
    try:
        cargo_order = CargoOrder(cargo_order_number, origin_code,
                                 destination_code, order_status, order_type,
                                 cargo_name, cargo_volume, cargo_weight,
                                 specified_arrival_time, consignor_name,
                                 consignor_telephone, consignee_name,
                                 consignee_telephone, fk_operator_id, remark,
                                 date.today())
        db.session.add(cargo_order)
        remark = None
        oflow_obj = OrderFlow(cargo_order_number, order_status, now_time,
                              remark, fk_operator_id)
        db.session.add(oflow_obj)
        oorecord_obj = ooRecord(cargo_order_number,
                                cs.ACTION_TYPE_INFO[u"创建货物订单"], now_time,
                                fk_operator_id, remark)
        db.session.add(oorecord_obj)
        db.session.commit()
        # 推送线路信息
        push_line_info(cargo_order_number, origin_code, destination_code)
        return cs.OK, cargo_order_number
    except:
        logger.error('create cargo order error: {}'.format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
Exemplo n.º 30
0
def modify_order_status(token, cargo_order_number, cargo_order_status, remark):
    """
    修改货物订单状态
    :param token:
    :param cargo_order_number:
    :param cargo_order_status:
    :param remark:
    :return: cs.OK , {}
    """
    try:
        user = hgetall(get_token(token))
        # 验证用户权限
        if (not user) or int(
                user['role_type']) not in cs.ACTION_CARGO_ORDER_ROLE:
            return cs.AUTH_ERROR, None

        cargo_order_obj = CargoOrder.query.filter_by(
            cargo_order_number=cargo_order_number).first()
        if not cargo_order_obj:
            return cs.NOT_CARGO_ORDER, None

        # 验证单号是否属于该商家
        if int(user['role_type']) == cs.USER_ROLE_INFO[u"商家"]:
            if cargo_order_obj:
                if cargo_order_obj.fk_operator_id != user['id']:
                    return cs.AUTH_ERROR, None
            else:
                return cs.NOT_CARGO_ORDER, {
                    'cargo_order_number': cargo_order_number
                }
        else:
            # 验证订单的始发地,目的地是否属于转运网点
            if user['fk_location_code'] not in [
                    cargo_order_obj.origin_code,
                    cargo_order_obj.destination_code
            ]:
                return cs.AUTH_ERROR, None
        cargo_order_status = int(cargo_order_status)
        # 验证用户操作与权限是否匹配
        if cargo_order_status not in cs.USER_ROLE_ACTION[int(
                user['role_type'])]:
            return cs.AUTH_ERROR, {'cargo_order_number': cargo_order_number}

        old_cargo_order_status = cargo_order_obj.order_status
        # 验证订单状态
        if cargo_order_status not in cs.CARGO_ORDER_STATUS_CHANGE[int(
                old_cargo_order_status)]:
            return cs.CARGO_ORDER_STATUS_ABNORMAL, {
                'cargo_order_number': cargo_order_number
            }
        cargo_order_obj.order_status = cargo_order_status
        cargo_order_obj.remark = remark

        now_time = datetime.now()
        fk_operator_id = user['id']
        # 添加订单流记录
        oflow_obj = OrderFlow(cargo_order_number, cargo_order_status, now_time,
                              remark, fk_operator_id)
        # 添加操作人记录
        print cs.ACTION_TYPE_INDEX[cargo_order_status]
        action = cs.ACTION_TYPE_INFO[cs.ACTION_TYPE_INDEX[cargo_order_status]]
        oorecord_obj = ooRecord(cargo_order_number, action, now_time,
                                fk_operator_id, remark)
        db.session.add(oorecord_obj)
        db.session.add(oflow_obj)
        db.session.commit()
        return cs.OK, {'cargo_order_number': cargo_order_number}
    except:
        logger.error('cancellation_cargo_order {}'.format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()