def signup_action(params): ''' 校验注册 :param params: :return: ''' username = params.get('username') password = params.get('password') email = params.get('email') phone = params.get('phone') # 用户名长度在 [1,30] 之间 if is_none(username) or not (check_len(username, 1, 'ge') and check_len(username, 30, 'le')): return param_err('用户名长度') # 密码长度在 [6-30] 之间 if is_none(password) or not (check_len(password, 6, 'ge') and check_len(password, 30, 'le')): return param_err('密码长度') if is_none(email) or not check_is_email(email): return param_err('邮箱') if is_none(phone) or not check_is_phone(phone): return param_err('手机号') return dict(type=True)
def entry_one_action(params): ''' 入栏一头猪 参数校验 :param params: :return: ''' pid = params.get('pid') animalnum = params.get('animalNum') earid = params.get('earId') stationid = params.get('stationId') if is_none(pid) or not check_len(pid, 15, 'le'): return param_err(define_name['pid']) if is_none(stationid): return param_err(define_name['station']) if not stationid_exist(stationid): return dict(type=False, err_msg=define_name['stationid'] + '不存在') if is_none(animalnum) or not check_len(animalnum, 15, 'le'): return param_err(define_name['animalnum']) if is_none(earid) or not check_len(earid, 12, 'le'): return param_err(define_name['earid']) return dict(type=True)
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)
def add_one_record_action(params): ''' 种猪一次采食,数据插入表中 参数校验 :param params: :return: ''' # 测定站只会将 earid 传输过来,从数据库中获取到 earid 对应的 pid,stationid,animalnum 等相关信息 earid = params.get('earid') stationid = params.get('stationid') food_intake = params.get('food_intake') weight = params.get('weight') body_long = params.get('body_long') body_width = params.get('body_width') body_height = params.get('body_height') body_temp = params.get('body_temp') env_temp = params.get('env_temp') env_humi = params.get('env_humi') start_time = params.get('start_time') end_time = params.get('end_time') if is_none(earid) or not check_len(earid, 12, 'eq'): return param_err(define_name['earid']) if is_none(stationid) or not check_len(stationid, 12, 'le'): return param_err(define_name['stationid']) if is_none(food_intake): return param_err(define_name_pigbase['food_intake']) if is_none(weight): return param_err(define_name_pigbase['weight']) if is_none(body_long): return param_err(define_name_pigbase['body_long']) if is_none(body_width): return param_err(define_name_pigbase['body_width']) if is_none(body_height): return param_err(define_name_pigbase['body_height']) # if is_none(body_temp): # return param_err(define_name_pigbase['body_temp']) # # if is_none(env_temp): # return param_err(define_name_pigbase['env_temp']) # # if is_none(env_humi): # return param_err(define_name_pigbase['env_humi']) if is_none(start_time): return param_err(define_name_pigbase['start_time']) if is_none(end_time): return param_err(define_name_pigbase['end_time']) return dict(type=True)
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('键名')
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)
def forget_pass_action(params): ''' 校验忘记密码 :param params: :return: ''' email = params.get('email') password = params.get('password') if is_none(email) or not check_is_email(email): return param_err('邮箱') if is_none(password) or not (check_len(password, 6, 'ge') and check_len(password, 30, 'le')): return param_err('密码长度') return dict(type=True)
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)
def signin_action(params): ''' 校验登录 :param params: :return: ''' username = params.get('username') password = params.get('password') # 用户名长度在 [1,30] 之间 if is_none(username) or not (check_len(username, 1, 'ge') and check_len(username, 30, 'le')): return param_err('用户名长度') # 密码长度在 [6-30] 之间 if is_none(password) or not (check_len(password, 6, 'ge') and check_len(password, 30, 'le')): return param_err('密码长度') return dict(type=True)
def total_perstation_action(params): stationid = params.get('stationId') time = params.get('time') if is_none(stationid) or not check_len(stationid, 12, 'le'): return param_err(define_name['stationid']) if is_none(time): return param_err('时间') return dict(type=True)
def delete_station_action(params): ''' 删除加测定站 的数据校验 :param params: :return: ''' stationid = params.get('stationid') if is_none(stationid) or not check_len(stationid, 12, 'le'): return param_err('测定站') return dict(type=True)
def exit_one_station_action(params): ''' 出栏一个测定站的所有猪 :param params: :return: ''' stationid = params.get('stationId') if is_none(stationid) or not check_len(stationid, 12, 'le'): return param_err(define_name['stationid']) if not stationid_exist(stationid): return dict(type=False, err_msg=define_name['stationid'] + '不存在') return dict(type=True)
def get_piglist_from_station_action(params): ''' 按测定站查询测定站下的所有猪信息 参数校验 :param params: :return: ''' stationid = params.get('stationId') if is_none(stationid) or not check_len(stationid, 12, 'le'): return param_err(define_name['stationid']) if not stationid_exist(stationid): return dict(type=False, err_msg=define_name['stationid'] + '不存在') return dict(type=True)
def insert_piginfo_action(params): ''' 插入种猪信息 :param params: 请求的 json 参数 :return: ''' earid = params.get('earid') stationid = params.get('stationid') foodintake = params.get('foodintake') weight = params.get('weight') bodylong = params.get('bodylong') bodywidth = params.get('bodywidth') bodyheight = params.get('bodyheight') bodytemperature = params.get('bodytemperature') stationtime = params.get('stationtime') if not check_exist(earid) or not check_len(earid, 12, 'le'): return param_err('耳标号') if not check_exist(stationid) or not check_len(stationid, 12, 'le'): return param_err('测定站id') if not check_exist(foodintake): return param_err('进食量') if not check_exist(weight): return param_err('体重') if not check_exist(bodylong): return param_err('体长') if not check_exist(bodywidth): return param_err('体宽') if not check_exist(bodyheight): return param_err('体高') if not check_exist(bodytemperature): return param_err('温度') if not check_exist(stationtime): return param_err('测定站的时间') return {'type': True}
def update_piginfo_action(params): ''' 更改一头种猪信息 参数校验 :param params: :return: ''' pid = params.get('pid') recordId = params.get('recordId') animalnum = params.get('animalNum') earid = params.get('earId') if is_none(pid) or not check_len(pid, 15, 'le'): return param_err(define_name['pid']) if is_none(animalnum) or not check_len(animalnum, 15, 'le'): return param_err(define_name['animalnum']) if is_none(earid) or not check_len(earid, 12, 'le'): return param_err(define_name['earid']) # 检测耳标号是否已经存在 # if earid_exist(earid): # return dict(type=False, err_msg=define_name['earid'] + '已经存在') return dict(type=True)
def daily_weight_gain_and_fcr_action(params): stationid = params.get('stationId') start_time = params.get('startTime') end_time = params.get('endTime') 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)
def get_station_weekly_assessment_info_action(params): ''' 测定站周采食量统计 参数校验 :param params: :return: ''' stationid = params.get('stationId') start_time = params.get('startTime') end_time = params.get('endTime') 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(define_name_pig_daily_assess['start_time']) if is_none(end_time): return param_err(define_name_pig_daily_assess['end_time']) return dict(type=True)
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)
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}