Exemplo n.º 1
0
def reset_meter(meter_info, user):
    """
    重启仪表
    :param meter_info:
    :param user: 当前登录的用户
    :return:
    """
    must_dict = {
        "meter_ids": ListCheck.check_is_int_list,
    }
    param_check(
        meter_info,
        must_dict,
    )

    meter_infos = conf_meter_api.find_infos_by_meter_ids(
        meter_info['meter_ids'])
    for meter_info in meter_infos:
        log_dict = {
            "opr_user_id": user['id'],
            "meter_id": meter_info['meter_id'],
            'opr_type': Operator.RESET,
            'val': ""
        }
        # 保证原子性
        with transaction.atomic():
            log = conf_log_api.add_opr_log(log_dict)
            opr = Operator.create_reset_opr(meter_info['dtu_no'],
                                            meter_info['address'], log.id,
                                            meter_info['meter_id'])
            app_opr_api.execute_remote_op(opr)
Exemplo n.º 2
0
def recharge_meter(meter_ids, money, user):
    """
    给仪表充值
    :param money: 充值的数量
    :param meter_ids: 充值的仪表id
    :param user: 当前登录的用户
    :return:
    """

    meter_infos = conf_meter_api.find_infos_by_meter_ids(meter_ids)

    for meter_info in meter_infos:
        log_dict = {
            "opr_user_id": user['id'],
            "meter_id": meter_info['meter_id'],
            'opr_type': Operator.RECHARGE,
            'val': money
        }
        # 保证原子性
        with transaction.atomic():
            log = conf_log_api.add_opr_log(log_dict)
            opr = Operator.create_recharge_opr(meter_info['dtu_no'],
                                               meter_info['address'], log.id,
                                               meter_info['meter_id'], money)
            app_opr_api.execute_remote_op(opr)
Exemplo n.º 3
0
def query_meter_data(meter_info, user, record_log=True):
    must_dict = {
        "meter_ids": ListCheck.check_is_int_list,
    }
    param_check(meter_info, must_dict)
    meter_infos = conf_meter_api.find_infos_by_meter_ids(
        meter_info['meter_ids'])

    for meter_info in meter_infos:
        dtu_no = meter_info['dtu_no']

        log_dict = {}
        if record_log:
            log_dict = {
                "opr_user_id": user['id'],
                "meter_id": meter_info['meter_id'],
                'opr_type': Operator.QUERY,
                'val': ""
            }
        # 保证原子性
        with transaction.atomic():

            log_id = None
            if record_log:
                log = conf_log_api.add_opr_log(log_dict)
                log_id = log.id

            opr = Operator.create_query_opr(dtu_no, meter_info['address'],
                                            log_id, meter_info['meter_id'])
            app_opr_api.execute_remote_op(opr)
Exemplo n.º 4
0
def update_flow_ratio(meter_info, user):
    """
    更新仪表流量系数
    :param meter_info:
    :param user: 当前登录的用户
    :return:
    """
    must_dict = {
        "id": int,
        "address": int,
        "dtu_no": int,
        "flow_ratio": float,
    }
    param_check(
        meter_info,
        must_dict,
    )

    dtu_no = meter_info['dtu_no']
    log_dict = {
        "opr_user_id": user['id'],
        "meter_id": meter_info['id'],
        'opr_type': Operator.SET_FLOW_RATIO
    }
    # 保证原子性
    with transaction.atomic():
        log = conf_log_api.add_opr_log(log_dict)
        opr = Operator.create_set_flow_ratio_opr(dtu_no, meter_info['address'],
                                                 log.id, meter_info['id'],
                                                 meter_info['flow_ratio'])
        app_opr_api.execute_remote_op(opr)
Exemplo n.º 5
0
def update_valve_state(meter_state_info, user):
    """
    更改阀门状态
    :param user: 当前登录的用户
    :param meter_state_info:
    :return:
    """
    must_dict = {
        "meter_ids": ListCheck.check_is_int_list,
        "valve_state": int,
    }
    param_check(
        meter_state_info,
        must_dict,
    )

    # 查找该流量计对应的阀门DTU
    meter_infos = conf_meter_api.find_infos_by_meter_ids(
        meter_state_info['meter_ids'])

    for meter_info in meter_infos:
        # 保证原子性
        with transaction.atomic():
            log_dict = {
                "opr_user_id": user['id'],
                "meter_id": meter_info['meter_id'],
            }
            if meter_state_info['valve_state'] == VALVE_STATE_OPEN:
                log_dict['opr_type'] = Operator.OPEN_VALVE
                log = conf_log_api.add_opr_log(log_dict)
                opr = Operator.create_open_valve_opr(meter_info['dtu_no'],
                                                     meter_info['address'],
                                                     log.id,
                                                     meter_info['meter_id'])
            else:
                log_dict['opr_type'] = Operator.CLOSE_VALVE
                log = conf_log_api.add_opr_log(log_dict)
                opr = Operator.create_close_valve_opr(meter_info['dtu_no'],
                                                      meter_info['address'],
                                                      log.id,
                                                      meter_info['meter_id'])

            app_opr_api.execute_remote_op(opr)
Exemplo n.º 6
0
def update_recharge_state(meter_state_info, user):
    """
    更新仪表充值状态
    :param user: 当前登录的用户
    :param meter_state_info:
    :return:
    """
    must_dict = {
        "meter_ids": ListCheck.check_is_int_list,
        "recharge_state": WhiteListCheck.check_recharge_state,
    }
    param_check(
        meter_state_info,
        must_dict,
    )

    meter_infos = conf_meter_api.find_infos_by_meter_ids(
        meter_state_info['meter_ids'])
    for meter_info in meter_infos:
        # 保证原子性
        with transaction.atomic():
            log_dict = {
                "opr_user_id": user['id'],
                "meter_id": meter_info['meter_id'],
            }
            if meter_state_info['recharge_state'] == RECHARGE_STATE_OPEN:
                log_dict['opr_type'] = Operator.OPEN_RECHARGE
                log = conf_log_api.add_opr_log(log_dict)
                opr = Operator.create_open_recharge_opr(
                    meter_info['dtu_no'], meter_info['address'], log.id,
                    meter_info['meter_id'])
            else:
                log_dict['opr_type'] = Operator.CLOSE_RECHARGE
                log = conf_log_api.add_opr_log(log_dict)
                opr = Operator.create_close_recharge_opr(
                    meter_info['dtu_no'], meter_info['address'], log.id,
                    meter_info['meter_id'])
            app_opr_api.execute_remote_op(opr)
Exemplo n.º 7
0
def update_meter(meter_info, user):
    """
    更新仪表信息
    :param meter_info:
    :param user:
    :return:
    """
    must_dict = {
        "id": int,
        "address": int,
        "dtu_no": int,
        "surplus_gas_limits": float,
    }
    optional_dict = {
        'remark': StrCheck.check_remark,
    }
    param_check(meter_info, must_dict, optional_dict)

    old_meter = conf_meter_api.find_meter_by_id(meter_info['id'])
    conf_meter_api.update_meter_info({
        "id":
        meter_info['id'],
        "surplus_gas_limits":
        meter_info['surplus_gas_limits'],
        "remark":
        meter_info.get('remark', '')
    })

    # 更改物理地址
    if old_meter.address != meter_info['address']:
        log_dict = {
            "opr_user_id": user['id'],
            "meter_id": meter_info['id'],
            "opr_type": Operator.SET_METER_ADDRESS,
        }
        # 保证原子性
        with transaction.atomic():
            log = conf_log_api.add_opr_log(log_dict)
            opr = Operator.create_set_meter_address_opr(
                meter_info['dtu_no'], old_meter.address, log.id,
                meter_info['id'], meter_info['address'])
            app_opr_api.execute_remote_op(opr)