Exemplo n.º 1
0
def update_kv_action(params):
    '''
    更改数据库的 kv 配置,处理之前的参数合格性校验
    :param params:
    :return:
    '''
    name = params.get('name')
    value = params.get('value')

    if name == cfg_keys.get('FAC_NUM'):
        if check_len(value, 4):
            return dict(type=True)
        else:
            return param_err('猪场代码')
    elif name == cfg_keys.get('SHOW_SELECT_LANGUAGE'):
        if check_in(value, ('false', 'true')):
            return dict(type=True)
        else:
            return param_err('显示选择语言')
    elif name == cfg_keys.get('SHOW_TIME_SYNC'):
        if check_in(value, ('false', 'true')):
            return dict(type=True)
        else:
            return param_err('显示时间同步')
    elif name == cfg_keys.get('PIG_BASE_DATA_FIELDS'):
        # value 是一个数组,数组中的所有制必须在执行的列中
        if type(value) == list\
            and check_arr_all_in(value, cfg_allowed_values.get('PIG_BASE_DATA_ALLOWED_FIELDS')):
            return dict(type=True)
        else:
            return param_err('种猪基础信息')

    return param_err('键名')
Exemplo n.º 2
0
def update_station_action(params):
    '''
    编辑加测定站 的数据校验
    :param params:
    :return:
    '''
    stationid = params.get('stationid')
    comment = params.get('comment')
    status = params.get('status')
    errorcode = params.get('errorcode')

    if is_none(stationid) or not check_len(stationid, 12, 'le'):
        # 必须有 测定站id
        return param_err('测定站')
    if not is_none(comment) and not check_len(comment, 50, 'le'):
        # 可以没有 comment,如果有,则必须限制长度
        return param_err('备注长度')
    if not is_none(status) and not check_in(status, ('on', 'off')):
        # 可以没有 status,如果有,则只能 on 或者 off
        return param_err('测定站状态')
    if not is_none(errorcode) and not check_is_errorcode(errorcode):
        # 可以没有 status,如果有,则只能 on 或者 off
        return param_err('故障码')

    return dict(type=True)
Exemplo n.º 3
0
def weight_change_action(params):
    r_type = params.get('type')
    start_time = params.get('startTime')
    end_time = params.get('endTime')
    stationid = params.get('stationId')
    pid = params.get('pid')

    if not check_in(r_type, ('station', 'pig')):
        return param_err('查询类型(测定站或者种猪)')

    if r_type == 'station':
        if is_none(stationid) or not check_len(stationid, 12, 'le'):
            return param_err(define_name['stationid'])

    if is_none(start_time):
        return param_err('开始时间')

    if is_none(end_time):
        return param_err('结束时间')

    if r_type == 'pig':
        if is_none(pid):
            return param_err('种猪 id')

    return dict(type=True)
Exemplo n.º 4
0
def add_station_action(params):
    '''
    添加测定站 的数据校验
    :param params:
    :return:
    '''
    stationid = params.get('stationid')
    comment = params.get('comment')
    status = params.get('status')

    if is_none(stationid) or not check_len(stationid, 12, 'le'):
        return param_err('测定站')
    if is_none(comment) or not check_len(comment, 50, 'le'):
        return param_err('备注长度')
    if is_none(status) or not check_in(status, ('on', 'off')):
        return param_err('测定站状态')

    return dict(type=True)
Exemplo n.º 5
0
def intake_frequency_in_day_interval_action(params):
    s_type = params.get('type')
    start_time = params.get('startTime')
    end_time = params.get('endTime')
    stationid = params.get('stationId')

    if not check_in(s_type, ('all', 'one')):
        return param_err('查询类型错误(一个或者所有测定站)')

    if s_type == 'one':
        if is_none(stationid) or not check_len(stationid, 12, 'le'):
            return param_err(define_name['stationid'])

    if is_none(start_time):
        return param_err('开始时间')

    if is_none(end_time):
        return param_err('结束时间')

    return dict(type=True)
Exemplo n.º 6
0
def stationinfo_action(params):
    '''
    插入测定站信息
    :param params: 请求的 json 参数
    :return:
    '''
    stationid = params.get('stationid')
    status = params.get('status')
    changetime = params.get('changetime')
    errorcode = params.get('errorcode')

    if not check_exist(stationid) or not check_len(stationid, 12, 'le'):
        return param_err('测定站id')
    if not check_exist(status) or not check_in(status, ('on', 'off')):
        return param_err('机器运行状态')
    if not check_exist(changetime) or not check_is_timestamp_integer(
            changetime):
        return param_err('状态变化时间')
    if not check_exist(errorcode) or not check_number_str_len(errorcode, 5):
        return param_err('故障编号')

    return {'type': True}