コード例 #1
0
ファイル: line_volume.py プロジェクト: xushuhai/OrderSystem
def line_volume_set(line_code, cargos_volume, cargos_weight, id):
    """

    :param line_code:
    :param cargos_volume:
    :param cargos_weight:
    :param id:
    :return:
    """
    try:
        line_volume_obj = LineVolume.query.filter_by(
            line_code=line_code).first()
        if line_volume_obj:
            line_volume_obj.pending_volume += int(cargos_volume)
            line_volume_obj.pending_weight += int(cargos_weight)
            line_volume_obj.id = id
        else:
            line_volume = LineVolume(line_code, cargos_volume, cargos_weight,
                                     id)
            db.session.add(line_volume)
        db.session.commit()
        logger.debug(
            'insert line_volume type 【line_code:{}; cargos_volume:{}; cargos_weight:{}; operator_id:{}】'
            .format(line_code, cargos_volume, cargos_weight, id))
        return cs.OK
    except:
        logger.error('insert line_volume err : {}'.format(
            traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()
コード例 #2
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()
コード例 #3
0
ファイル: location.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #4
0
ファイル: auth.py プロジェクト: xushuhai/OrderSystem
def modify_password(username, old_password, new_password):
    """
    修改密码
    :param username:
    :param old_password:
    :param new_password:
    :return:cs.OK
    """
    user = User.query.filter_by(username=username).first()
    m2 = hashlib.md5()
    m2.update(old_password)
    if user.password == m2.hexdigest():
        try:
            m3 = hashlib.md5()
            m3.update(new_password)
            user.password = m3.hexdigest()
            db.session.commit()
            return cs.OK, None
        except:
            logger.error('modify password error:{}'.format(traceback.format_exc(), ))
            raise
        finally:
            db.session.remove()
    else:
        return cs.PASSWD_ERR, None
コード例 #5
0
ファイル: location.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #6
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()
コード例 #7
0
ファイル: auth.py プロジェクト: xushuhai/OrderSystem
def reset_password(username, new_password, verifying_code):
    """
    短信找回密码
    :param username:
    :param new_password:
    :param verifying_code:
    :return:cs.OK
    """
    verifying = rget(get_sms(username))
    if not verifying or verifying != verifying_code:
        return cs.VERIFYING_ERROR, None
    user = User.query.filter_by(username=username).first()
    if user:
        try:
            m2 = hashlib.md5()
            m2.update(new_password)
            user.password = m2.hexdigest()
            db.session.commit()
            return cs.OK, None
        except:
            logger.error('reset password err:{}'.format(traceback.format_exc(), ))
            raise
        finally:
            db.session.remove()
    else:
        return cs.NO_USER_EXIST, None
コード例 #8
0
ファイル: auth.py プロジェクト: xushuhai/OrderSystem
def get_verifying_code(telephone):
    """
    根据手机号码发送验证码
    :param telephone:
    :return:cs.OK
    """
    verifying_telephone = r'^1[34578]\d{9}'
    result = re.findall(verifying_telephone, telephone)
    if result:
        my_str = ''
        for i in range(6):
            my_str += str(random.randint(0, 9))
        params = dict(code=my_str)
        params = json.dumps(params)
        celery.send_task(CELERY_ROUTE_CREATE,
                         args=[telephone, SIGN_NAME, TEMPLATE_CODE, params], queue=QUEUE)
        # 将验证码插入redis中,并设置销毁时间
        try:
            rset(get_sms(telephone), my_str)
            rexpire(get_sms(telephone), SMS_EXPIRE_TIME)
        except:
            logger.error('insert verifying code in redis err:{}'.format(traceback.format_exc(), ))
            raise
        return cs.OK, my_str
    else:
        return cs.PARAMS_ERROR, None
コード例 #9
0
ファイル: waybill.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #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()
コード例 #11
0
ファイル: waybill.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #12
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()
コード例 #13
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()
コード例 #14
0
ファイル: auth.py プロジェクト: xushuhai/OrderSystem
def register_user(verifying_code, telephone, name, username, password, mobile, role_type, fk_location_code, fk_plate):
    """
    注册
    :param verifying_code:
    :param telephone:
    :param name:
    :param username:
    :param password:
    :param mobile:
    :param role_type:
    :param fk_location_code:
    :param fk_plate:
    :return: cs.OK
    """
    verifying = rget(get_sms(telephone))
    if not verifying or verifying != verifying_code:
        return cs.VERIFYING_ERROR, None
    user = User.query.filter_by(username=username).first()
    if user:
        return cs.USER_EXIST, None
    print role_type
    print cs.USER_ROLE_TYPE.keys()
    if int(role_type) not in cs.USER_ROLE_TYPE.keys():
        return cs.AUTH_ERROR, None
    if int(role_type) in [cs.USER_ROLE_INFO[u"承运商"], cs.USER_ROLE_INFO[u"商家"]]:
        fk_location_code = None
    m2 = hashlib.md5()
    m2.update(password)
    password = m2.hexdigest()
    try:
        user = User(name, username, password, mobile, role_type, fk_location_code, fk_plate)
        db.session.add(user)
        db.session.commit()
        return cs.OK, None
    except:
        logger.error('register user error:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.remove()
コード例 #15
0
ファイル: location.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #16
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()
コード例 #17
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()
コード例 #18
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()
コード例 #19
0
def cache_exception(e):
    logger.error('Redis Exception:{}'.format(e))
    return rw(cs.DB_ERROR)
コード例 #20
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()
コード例 #21
0
ファイル: exceptions.py プロジェクト: xushuhai/OrderSystem
 def __init__(self, value=''):
     self.value = value
     logger.error("AuthError:{value}".format(value=str(value)))
コード例 #22
0
ファイル: waybill.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #23
0
ファイル: waybill.py プロジェクト: xushuhai/OrderSystem
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()
コード例 #24
0
def create_line(token, origin_code, destination_code, line_status, line_type,
                line_kilometre, line_runtime, location_list):
    """
    创建线路信息
    :param token:
    :param origin_code:
    :param destination_code:
    :param line_status:
    :param line_type:
    :param line_kilometre:
    :param line_runtime:
    :param location_list:
    :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
        # 验证始发地目的地
        origin_location = get_location(origin_code)
        destination_location = get_location(destination_code)
        if not origin_location and not destination_location:
            return cs.LOCATION_CODE_ERR, None

        # 验证径停点 空校验,正确性校验
        if not location_list:
            return cs.LOCATION_INFO_ERR, None
        for item in list(location_list):

            location = get_location(int(item['location_code']))
            if not location:
                return cs.LOCATION_CODE_ERR, {
                    'location_code': item['location_code']
                }

        # 生成线路编码
        line_code = "MOT{}TO{}".format(origin_code, destination_code)
        line_code_count = db.session.query(Line.id).filter(
            Line.line_code.like('%' + str('MOT' + origin_code + 'TO' +
                                          destination_code) + '%')).count()
        amounter = str(line_code_count + 1).zfill(5)
        line_code = "{}{}".format(line_code, amounter)

        # 生成线路名称
        origin_name = origin_location.location_name
        destination_name = destination_location.location_name
        line_name = "{}-{}".format(origin_name, destination_name)
        location_number = len(location_list)
        # 添加线路信息
        line = Line(line_code, line_name, origin_code, destination_code,
                    line_status, line_type, line_kilometre, line_runtime,
                    location_number, user['id'])

        # 添加径停点信息
        for item in location_list:
            line_location = LineLocations(line_code, origin_code,
                                          destination_code,
                                          item['location_code'],
                                          item['sequence'],
                                          cs.LINE_LOCATION_STATUS_INFO[u"启用"],
                                          user['id'])
            db.session.add(line_location)
        db.session.add(line)
        db.session.commit()
        return cs.OK, {'line_code': line_code}
    except:
        logger.error('create_line err:{}'.format(traceback.format_exc(), ))
        raise
    finally:
        db.session.rollback()