diff --git a/aore/phias.py b/aore/phias.py index 132e071..36cf659 100644 --- a/aore/phias.py +++ b/aore/phias.py @@ -30,6 +30,14 @@ class App: return json.dumps(App._factory.normalize(aoid)) + @Route(r'/aoid2aoguid/') + class Convert(object): + def get(self, aoguid): + response.content_type = 'application/json' + response.set_header('Access-Control-Allow-Origin', '*') + + return json.dumps(App._factory.convert(aoguid)) + @Route(r'/find/') class Find(object): def get(self, text): diff --git a/aore/search/fiasfactory.py b/aore/search/fiasfactory.py index a5f97f3..87d1a01 100644 --- a/aore/search/fiasfactory.py +++ b/aore/search/fiasfactory.py @@ -17,6 +17,7 @@ class FiasFactory: self.searcher = SphinxSearch(self.db) self.expand_templ = template('aore/templates/postgre/expand_query.sql', aoid="//aoid") self.normalize_templ = template('aore/templates/postgre/normalize_query.sql', aoid="//aoid") + self.convert_templ = template('aore/templates/postgre/convert_query.sql', aoid="//aoid") self.gettext_templ = template('aore/templates/postgre/gettext_query.sql', aoid="//aoid") # Проверка, что строка является действительым UUID v4 @@ -84,6 +85,27 @@ class FiasFactory: else: return rows[0] + # Преобразует AOID в AOGUID + def convert(self, aoid: str): + try: + self.__check_param(aoid, "uuid") + + sql_query = self.convert_templ.replace("//aoid", aoid) + rows = self.db.get_rows(sql_query, True) + + assert len(rows), "Record with this AOID not found in DB" + except Exception as err: + if BasicConfig.logging: + logging.error(traceback.format_exc()) + if BasicConfig.debug_print: + traceback.print_exc() + return dict(error=str(err)) + + if len(rows) == 0: + return [] + else: + return rows[0] + # Разворачивает AOID в представление (перед этим нормализует) def expand(self, aoid_guid): try: diff --git a/aore/templates/postgre/convert_query.sql b/aore/templates/postgre/convert_query.sql new file mode 100644 index 0000000..0356207 --- /dev/null +++ b/aore/templates/postgre/convert_query.sql @@ -0,0 +1 @@ +SELECT AOGUID FROM "ADDROBJ" WHERE AOID=(SELECT AOID FROM "ADDROBJ" WHERE AOID='{{ aoid }}' OR AOGUID='{{ aoid }}') AND ACTSTATUS=True AND LIVESTATUS=True AND NEXTID IS NULL LIMIT 1; \ No newline at end of file