Exemple #1
0
 def search(self):
     self.apis_copy['value'] = 'aqdflv'
     from utils.db_connection import fx_engine
     from utils.results2df import results2df
     results = fx_engine.execute(self.sql)
     data = results2df(results, self.columns)
     self.df = data
Exemple #2
0
    def search(self):

        from utils.db_connection import fx_engine
        from utils.results2df import results2df

        results = fx_engine.execute(self.sql)
        data = results2df(results, self.columns)
        self.df = data
    def search(self):
        # self.apis_copy["xfjc"] = "jssllv"

        sql_list = self.apis_copy['ext'].split('/')
        Cqh_sql_map = {}
        for item in sql_list:
            if 'shej' in item:
                Cqh_sql_map['shej_02'] = item
            elif 'shij' in item:
                Cqh_sql_map['shij_02'] = item
            elif 'xj' in item:
                Cqh_sql_map['xj_02'] = item
            else:
                Cqh_sql_map['all'] = item

        # if g.get('before_param_trans')['bmjb'] == '省级':
        #     bmjb = 'shej_02'
        # elif g.get('before_param_trans')['bmjb'] == '市级':
        #     bmjb = 'shi_02'
        # elif g.get('before_param_trans')['bmjb'] == '县级':
        #     bmjb = 'xj_02'
        # else:
        #     bmjb = 'all'
        #
        # if bmjb:
        #     sql_item = Cqh_sql_map[bmjb] if bmjb in Cqh_sql_map else Cqh_sql_map['all']
        # else:
        #     Cqh_level = get_qh_level(g.get('before_param_trans')['Cqh'])
        #     sql_item = Cqh_sql_map[Cqh_level] if Cqh_level in Cqh_sql_map else Cqh_sql_map['all']

        sql_item = sql_list[0]
        sql_map = get_sql_map(DEBUG)
        # 按期答复率为3-4(市)3-2(省)

        from utils.db_connection import fx_engine
        from utils.results2df import results2df

        sql, columns = sql_map[sql_item]
        self.apis_copy['value'] = 'aqdflv'

        from flask import g
        results = fx_engine.execute(
            sql.format(**g.get("reqdicts_before_pt")).format(**self.apis_copy))
        data = results2df(results, columns)
        self.df = data
Exemple #4
0
def get_initdict_from_sql_mode(results, format_pool_sql):
    """
     "full": {"name": "{INITIALIZATION}['xfxs']", "value": [0], "query": "{INITIALIZATION}['xfxs']"}
    """
    full = results.get("full", {})
    init_dicts = {}  # 最终的需要做笛卡尔积映射的字段取值字典
    followers = {
    }  # 这里面的字段不用做笛卡尔积,和前面字段取值相同如    {"query": "$name"}  query的取值和name的取值相同
    for k, v in full.items():  # {"name": "xfxs", "query": "xfxs"}
        if isinstance(v, list):
            init_dicts[k] = v
        elif isinstance(v, str):
            from app import app
            if v.startswith("$"):
                followers.setdefault(v[1:], [])
                followers[v[1:]].append(k)
            elif v.startswith("fx_db_sql:"):
                sql = v.replace("fx_db_sql:", "").format(**format_pool_sql)
                from utils.db_connection import fx_engine
                try:
                    res = fx_engine.execute(sql)
                except:
                    return 400, f"PluginSQLError: There must be some error in the sql {sql}", {}
                from utils.get_unilist import get_unilist
                init_dicts[k] = get_unilist([i[0] for i in res if i[0]])
            elif v.startswith("zb_db_sql:"):
                sql = v.replace("zb_db_sql:", "").format(**format_pool_sql)
                from utils.db_connection import zb_engine
                try:
                    res = zb_engine.execute(sql)
                except:
                    return 400, f"PluginSQLError: There must be some error in the sql {sql}", {}
                from utils.get_unilist import get_unilist
                init_dicts[k] = get_unilist([i[0] for i in res if i[0]])

            elif v not in app.config.get("INITIALIZATION"):
                return 400, f"PluginSQLModeError: full params point to wrong direction {v}", {}
            else:
                init_dicts[k] = app.config.get("INITIALIZATION").get(v)
        else:
            return 400, f"PluginSQLModeError: full params contains invalid key {k}", {}
    return 200, "success", {"init_dicts": init_dicts, "followers": followers}