Example #1
0
def update_valve_address(valve_info):
    must_dict = {
        "id": int,
        "address": int,
    }
    param_check(valve_info, must_dict)

    conf_valve_api.update_valve(valve_info)
Example #2
0
def update_valve_dtu(valve_info):
    must_dict = {
        "id": int,
        "dtu_id": int,
    }
    param_check(valve_info, must_dict)

    conf_valve_api.update_valve(valve_info)
Example #3
0
def add_meter_state(state_info):
    must_dict = {
        "meter_id": int,
    }
    param_check(state_info, must_dict)

    state = MeterState.objects.create(**state_info)

    return state
Example #4
0
def edit_auth(auth_info):

    must_dict = {
        "id": int,
    }
    optional_dict = {
        "remark": StrCheck.check_remark,
    }
    param_check(auth_info, must_dict, optional_dict, extra=True)

    core.edit_auth(auth_info)
Example #5
0
def update_meter_data(meter_id, data):
    """
    更新仪表实时信息
    :param meter_id:
    :param data:
    :return:
    """
    must_dict = {
        "address": int,
        "opr_type": WhiteListCheck.check_opr_type,
    }

    param_check(data, must_dict, extra=True)
    meter_data = {'last_update_time': datetime.datetime.now()}

    if data['opr_type'] == Operator.QUERY:
        status = data['data'].pop('status')
        meter_data.update(data['data'])
        conf_state_api.update_meter_state(meter_id, status)

    # 更新仪表物理地址
    elif data['opr_type'] == Operator.SET_METER_ADDRESS:
        meter_data.update({'address': data['data']})

    # 更新仪表流量系数
    elif data['opr_type'] == Operator.SET_FLOW_RATIO:
        meter_data.update({'flow_ratio': data['data']})

    # 更新剩余气量
    elif data['opr_type'] == Operator.RECHARGE:
        surplus_gas = conf_meter_api.get_meter_surplus_gas(meter_id)
        meter_data.update({'surplus_gas': int(surplus_gas + data['data'])})

    # 更新阀门状态
    elif data['opr_type'] == Operator.OPEN_VALVE:
        conf_state_api.update_meter_state(meter_id,
                                          {'valve_state': VALVE_STATE_OPEN})

    # 更新阀门状态
    elif data['opr_type'] == Operator.CLOSE_VALVE:
        conf_state_api.update_meter_state(meter_id,
                                          {'valve_state': VALVE_STATE_CLOSE})

    # 更新预充值状态
    elif data['opr_type'] == Operator.OPEN_RECHARGE:
        conf_state_api.update_meter_state(
            meter_id, {'recharge_state': RECHARGE_STATE_OPEN})

    # 更新预充值状态
    elif data['opr_type'] == Operator.CLOSE_RECHARGE:
        conf_state_api.update_meter_state(
            meter_id, {'recharge_state': RECHARGE_STATE_CLOSE})

    conf_meter_api.update_meter_data(meter_id, meter_data)
Example #6
0
def create_auth_category(category):

    must_dict = {
        'name': StrCheck.check_auth_category_name,
    }
    optional_dict = {
        'remark': StrCheck.check_remark,
    }
    param_check(category, must_dict, optional_dict)

    core.create_auth_category(category)
Example #7
0
def update_data_field(field_info):

    must_dict = {
        'id': int,
        'begin_address': str,
        'end_address': str,
    }
    param_check(field_info, must_dict, extra=True)

    core.transfer_display_to_data(field_info)
    core.update_data_field(field_info)
Example #8
0
def update_system_setting(conf_info):
    """
    更改系统设置
    :return:
    """
    must_dict = {
        "name": StrCheck.check_configure_name,
        "val": StrCheck.check_value,
    }
    param_check(conf_info, must_dict)

    conf_configure_api.update_configure(conf_info)
Example #9
0
def update_control_register(register_info):

    must_dict = {
        'id': int,
        'field_val': str,
        'const_data': str,
        'remark': StrCheck.check_remark,
    }
    param_check(register_info, must_dict, extra=True)

    core.transfer_display_to_data(register_info)
    core.update_control_register(register_info)
Example #10
0
def update_meter_info(meter_info):
    must_dict = {
        "id": int,
    }
    optional_dict = {
        "surplus_gas_limits": float,
        "remark": StrCheck.check_remark,
    }
    param_check(meter_info, must_dict, optional_dict)

    old_meter = find_meter_by_id(meter_info['id'])
    core.update_meter(old_meter, meter_info)
Example #11
0
def add_meter(meter_info):
    must_dict = {
        "dtu_id": int,
        "address": int,
        "surplus_gas_limits": float,
    }
    optional_dict = {
        "remark": StrCheck.check_remark,
    }
    param_check(meter_info, must_dict, optional_dict)

    return core.add_meter(meter_info)
Example #12
0
def add_batch_meter_history_data(data_infos):
    """
    批量添加流量计历史数据
    :param data_infos:
    :return:
    """
    history_datas = []
    for data_info in data_infos:
        must_dict = {"meter_id": int, "data": float, "time": datetime.date}
        param_check(data_info, must_dict)
        history_datas.append(MeterHistoryData(**data_info))

    MeterHistoryData.objects.bulk_create(history_datas)
Example #13
0
def update_dtu_region(dtu_info):

    must_dict = {
        "id": int,
    }
    optional_dict = {
        'remark': StrCheck.check_remark,
    }
    param_check(dtu_info, must_dict, optional_dict)

    dtu = conf_dtu_api.find_dtu_by_id(dtu_info['id'])

    core.update_dtu(dtu, dtu_info)
Example #14
0
def add_system_log(log_dict):
    must_dict = {
        'action_type': StrCheck.check_action_type,
        'opr_user_id': int,
        'opr_time': datetime.datetime,
        'state': WhiteListCheck.check_opr_state,
    }
    optional_dict = {
        "msg": StrCheck.check_msg,
    }
    param_check(log_dict, must_dict, optional_dict)

    conf_log_api.add_system_log(log_dict)
Example #15
0
def create_authority(authority):

    must_dict = {
        "name": StrCheck.check_auth_name,
        "permission_action": StrCheck.check_auth_permission_action,
    }
    optional_dict = {
        "remark": StrCheck.check_remark,
    }
    param_check(authority, must_dict, optional_dict)

    core.check_auth_unique(authority)
    core.create_authority(authority)
Example #16
0
def update_data_field(field_info):

    must_dict = {
        'id': int,
        'begin_address': int,
        'end_address': int,
    }
    param_check(field_info, must_dict, extra=True)

    # 保证原子性
    with transaction.atomic():
        core.update_data_field(field_info)
        # 直接删除所有关于数据域的缓存
        cache.delete('field_*')
Example #17
0
def check_user_unique(user_info):
    """
    校验新创建的用户是否唯一
    :param user_info:
    :return:
    """
    must_dict = {
        "email": StrCheck.check_email,
        "phone": StrCheck.check_phone,
    }
    param_check(user_info, must_dict, None, extra=True)

    check_email_unique(user_info.get('email'))
    check_phone_unique(user_info.get('phone'))
Example #18
0
def add_opr_log(log):

    must_dict = {
        "opr_type": WhiteListCheck.check_opr_type,
        "opr_user_id": int,
        "meter_id": int,
    }
    if log.get('val') is not None:
        log['val'] = str(log['val'])
    param_check(log, must_dict=must_dict, extra=True)

    log['state'] = OprLog.WAITE_STATE
    log['opr_time'] = datetime.datetime.now()
    return core.add_opr_log(log)
Example #19
0
def update_dtu_region(region_info):

    must_dict = {
        "id": int,
        "total_num": IntCheck.check_is_positive_int,
    }
    param_check(region_info, must_dict)

    region = conf_region_api.find_region_by_id(region_info['id'])
    total_num = region_info['total_num']
    # 先判断total_num是否合法
    if core.is_total_num_legal(region, total_num):
        core.update_region_total_num(region, total_num)
    else:
        raise ParameterErrorException("DTU最大数目:{},太大,更新失败!".format(total_num))
Example #20
0
def add_region(region):
    """
    添加一个dtu区间
    :return:
    """
    must_dict = {
        "manufacturer_id": int,
        "total_num": int,
    }
    param_check(region, must_dict)

    region_info = core.find_can_alloc_region(region['total_num'])
    region_info['manufacturer_id'] = region['manufacturer_id']
    region_info['used_num'] = 0
    core.add_region(region_info)
Example #21
0
def create_dtu_user(dtu_user_info):
    """
    创建DTU用户账号
    :param dtu_user_info:
    :return:
    """
    must_dict = {
        "name": StrCheck.check_admin_name,
        "email": StrCheck.check_email,
        "phone": StrCheck.check_phone,
    }
    optional_dict = {"remark": StrCheck.check_remark}
    param_check(dtu_user_info, must_dict, optional_dict)

    user_core.create_dtu_user(dtu_user_info)
Example #22
0
def update_configure(conf_info):

    must_dict = {
        "name": str,
        "val": StrCheck.check_value,
    }
    param_check(conf_info, must_dict)

    conf = Configure.objects.get(name=conf_info['name'])
    conf.val = conf_info['val']

    with transaction.atomic():
        conf.save()
        # 更新缓存
        cache.set_hash('configure', conf_info['name'], conf_info['val'])
Example #23
0
def edit_role(role_info):

    must_dict = {
        "name": StrCheck.check_role_name,
        "label": StrCheck.check_role_name,
        "remark": StrCheck.check_remark
    }
    param_check(role_info, must_dict)

    role = conf_role_api.get_role(role_info['name'])

    role.label = role_info['label']
    role.remark = role_info['remark']

    role.save()
Example #24
0
def add_region(region_info):
    """
    添加区间
    :param region_info:
    :return:
    """
    must_dict = {
        "manufacturer_id": int,
        "left": int,
        "right": int,
        "used_num": int,
    }
    param_check(region_info, must_dict)

    core.add_region(region_info)
Example #25
0
def add_system_log(log):

    must_dict = {
        "action_type": StrCheck.check_action_type,
        "opr_user_id": int,
        "opr_time": datetime.datetime,
        "state": WhiteListCheck.check_opr_state,
    }
    optional_dict = {
        "msg": StrCheck.check_msg,
    }

    param_check(log, must_dict=must_dict, optional_dict=optional_dict)

    return core.add_system_log(log)
Example #26
0
def create_navigation_bar(navigation_bar_info):
    """
    创建一个导航栏对象
    :param navigation_bar_info:
    :return:
    """
    must_dict = {
        "name": StrCheck.check_navigation_bar_name,
        "icon": StrCheck.check_navigation_bar_icon,
        "url": StrCheck.check_url,
    }
    param_check(navigation_bar_info, must_dict)

    core.check_navigation_bar_unique(navigation_bar_info)
    core.create_navigation_bar(navigation_bar_info)
Example #27
0
def create_manufacturer(manufacturer_info):
    """
    创建厂商账号
    :param manufacturer_info:
    :return:
    """
    must_dict = {
        "name": StrCheck.check_admin_name,
        "email": StrCheck.check_email,
        "phone": StrCheck.check_phone,
    }
    optional_dict = {"remark": StrCheck.check_remark}
    param_check(manufacturer_info, must_dict, optional_dict)

    return user_core.create_manufacturer(manufacturer_info)
Example #28
0
def add_unexecuted_operator(opr):
    """
    添加新的操作到待执行的队列中
    :param opr:
    :return:
    """
    must_dict = {
        'dtu_no': int,
        'address': int,
        'opr_type': WhiteListCheck.check_opr_type,
    }
    param_check(opr, must_dict, extra=True)
    opr['opr_time'] = time.time()

    logger.info("添加未执行操作:{}".format(opr))
    UnExecutedOpr.objects.create(**opr)
Example #29
0
def add_wait_operator(opr):
    """
    添加到等待执行结果的队列中
    :param opr:
    :return:
    """
    must_dict = {
        'dtu_no': int,
        'address': int,
        'opr_type': WhiteListCheck.check_opr_type,
    }
    param_check(opr, must_dict, extra=True)

    opr['opr_time'] = time.time()

    WaitOpr.objects.create(**opr)
Example #30
0
def add_unread_alarm(unread_alarm_dict):
    must_dict = {
        "user_id": int,
        "alarm_log": AlarmLog,
    }
    param_check(unread_alarm_dict, must_dict)

    user_id = unread_alarm_dict['user_id']
    alarm = unread_alarm_dict['alarm_log']
    now = datetime.datetime.now()
    unread_alarm_dict['unique_flag'] = '{}_{}_{}_{}_{}_{}'.format(
        now.year, now.month, now.day, user_id, alarm.meter.id,
        alarm.alarm_type)
    log_read = AlarmLogReader.objects.create(**unread_alarm_dict)

    return log_read