Example #1
0
def resp_wrapper(code, rval=None):
    response_info = ' '.join(
        ['path:', request.path, 'code',
         str(code), 'data',
         str(rval)])
    logger.info('\nResponse:{}'.format(response_info))
    return jsonify(({'code': code, 'errmsg': cs.ERR_MSG[code], 'data': rval}))
Example #2
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
Example #3
0
def create_user_send_sms(telephone,
                         sign_name,
                         template_code,
                         template_param=None):
    business_id = uuid.uuid1()
    result = send_sms(business_id, telephone, sign_name, template_code,
                      template_param)
    result = json.loads(result)
    if str(result['Message']) == 'OK':
        logger.info(
            'SMS sending success Message:{}, mobile:{}, param:{} '.format(
                result['Message'], telephone, template_param))
    else:
        logger.info('SMS sending failure Message:{}, mobile:{}'.format(
            result['Message'], telephone))
Example #4
0
 def decorator(*args, **kwargs):
     start_t = time.time()
     func_return = f(*args, **kwargs)
     end_t = time.time()
     logger.info('Cost time:{}ms\n'.format(end_t - start_t))
     if hasattr(func_return, 'headers'):
         try:
             header = [("Access-Control-Allow-Origin", "*"),
                       ('Access-Control-Allow-Methods',
                        'PUT,GET,POST,DELETE'),
                       ('Access-Control-Allow-Headers',
                        "Referer, Accept, Origin, User-Agent")]
             func_return.headers.__dict__.get('_list').extend(header)
             # func_return.headers.__dict__.get('_list').addAll(header)
         except AttributeError, e:
             logger.warning(e)
Example #5
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
Example #6
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
Example #7
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)
Example #8
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
    }