feat: add route to convert aoid2aoguid
This commit is contained in:
parent
966bec093f
commit
3b47bfd3a3
@ -30,6 +30,14 @@ class App:
|
|||||||
|
|
||||||
return json.dumps(App._factory.normalize(aoid))
|
return json.dumps(App._factory.normalize(aoid))
|
||||||
|
|
||||||
|
@Route(r'/aoid2aoguid/<aoguid:re:[\w]{8}(-[\w]{4}){3}-[\w]{12}>')
|
||||||
|
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/<text>')
|
@Route(r'/find/<text>')
|
||||||
class Find(object):
|
class Find(object):
|
||||||
def get(self, text):
|
def get(self, text):
|
||||||
|
@ -17,6 +17,7 @@ class FiasFactory:
|
|||||||
self.searcher = SphinxSearch(self.db)
|
self.searcher = SphinxSearch(self.db)
|
||||||
self.expand_templ = template('aore/templates/postgre/expand_query.sql', aoid="//aoid")
|
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.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")
|
self.gettext_templ = template('aore/templates/postgre/gettext_query.sql', aoid="//aoid")
|
||||||
|
|
||||||
# Проверка, что строка является действительым UUID v4
|
# Проверка, что строка является действительым UUID v4
|
||||||
@ -84,6 +85,27 @@ class FiasFactory:
|
|||||||
else:
|
else:
|
||||||
return rows[0]
|
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 в представление (перед этим нормализует)
|
# Разворачивает AOID в представление (перед этим нормализует)
|
||||||
def expand(self, aoid_guid):
|
def expand(self, aoid_guid):
|
||||||
try:
|
try:
|
||||||
|
1
aore/templates/postgre/convert_query.sql
Normal file
1
aore/templates/postgre/convert_query.sql
Normal file
@ -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;
|
Loading…
x
Reference in New Issue
Block a user