# -*- coding: utf-8 -*-

from utils.redis.connect import r
from utils.redis.rkeys import BOX_PROGRAM_VERSION_INFO


def set_box_program_version():
    """ 设置 BOX 程序版本信息 """
    from operation.models import BoxProgramVersionInfo
    try:
        bpverion = BoxProgramVersionInfo.objects.filter(status=True)[0].data
    except IndexError:
        bpverion = {}
    r.setjson(BOX_PROGRAM_VERSION_INFO, bpverion)
    return bpverion


def get_box_program_version():
    """ 获取 BOX 程序版本信息 """
    return r.getjson(BOX_PROGRAM_VERSION_INFO) or set_box_program_version()
