|
|
@ -1,5 +1,6 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
|
|
|
|
|
@ -10,22 +11,24 @@ from website import settings
|
|
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
from website.service import enterprise
|
|
|
|
from website.service import enterprise
|
|
|
|
from website.util import shortuuid, aes
|
|
|
|
from website.util import shortuuid, aes
|
|
|
|
|
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EntityIndexHandler(APIHandler):
|
|
|
|
class EntityIndexHandler(APIHandler):
|
|
|
|
"""首页"""
|
|
|
|
"""首页"""
|
|
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
@authenticated
|
|
|
|
def post(self):
|
|
|
|
async def post(self):
|
|
|
|
pageNo = self.get_int_argument("pageNo", 1)
|
|
|
|
pageNo = self.get_int_argument("pageNo", 1)
|
|
|
|
pageSize = self.get_int_argument("pageSize", 10)
|
|
|
|
pageSize = self.get_int_argument("pageSize", 10)
|
|
|
|
name = self.tostr(self.get_escaped_argument("name", ""))
|
|
|
|
name = self.tostr(self.get_escaped_argument("name", ""))
|
|
|
|
|
|
|
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
sql_text = "select id, name, industry, logo, create_time from enterprise where 1=1 "
|
|
|
|
sql_text = "select id, suid, name, industry, logo, create_time from enterprise where 1=1 "
|
|
|
|
param = {}
|
|
|
|
param = {}
|
|
|
|
|
|
|
|
|
|
|
|
count_sql_text = "select count(id) from enterprise "
|
|
|
|
count_sql_text = "select count(id) c from enterprise where 1=1 "
|
|
|
|
count_param = {}
|
|
|
|
count_param = {}
|
|
|
|
|
|
|
|
|
|
|
|
if name:
|
|
|
|
if name:
|
|
|
@ -45,26 +48,64 @@ class EntityIndexHandler(APIHandler):
|
|
|
|
cur = conn.execute(text(sql_text), param)
|
|
|
|
cur = conn.execute(text(sql_text), param)
|
|
|
|
result = db_mysql.to_json_list(cur)
|
|
|
|
result = db_mysql.to_json_list(cur)
|
|
|
|
|
|
|
|
|
|
|
|
count = conn.execute(text(count_sql_text), count_param).fetchone()[0]
|
|
|
|
cur_count = conn.execute(text(count_sql_text), count_param)
|
|
|
|
logging.info(count)
|
|
|
|
count = db_mysql.to_json(cur_count)
|
|
|
|
logging.info(result)
|
|
|
|
count = count["c"] if count else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# data_index = [item["id"] for item in result]
|
|
|
|
data = []
|
|
|
|
data = []
|
|
|
|
for item in result:
|
|
|
|
# for item in result:
|
|
|
|
modelCount = enterprise.get_enterprise_model_count(item["id"])
|
|
|
|
# modelCount = enterprise.get_enterprise_model_count(item["id"])
|
|
|
|
deviceCount = enterprise.get_enterprise_device_count(item["id"])
|
|
|
|
# deviceCount = enterprise.get_enterprise_device_count(item["id"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# data.append(
|
|
|
|
|
|
|
|
# {
|
|
|
|
|
|
|
|
# "id": item["id"],
|
|
|
|
|
|
|
|
# "name": item["name"],
|
|
|
|
|
|
|
|
# "industry": consts.industry_map[item["industry"]],
|
|
|
|
|
|
|
|
# "modelCount": modelCount,
|
|
|
|
|
|
|
|
# "deviceCount": deviceCount,
|
|
|
|
|
|
|
|
# "logo": item["logo"],
|
|
|
|
|
|
|
|
# "createTime": str(item["create_time"]),
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# with ThreadPoolExecutor() as executor:
|
|
|
|
|
|
|
|
|
|
|
|
data.append(
|
|
|
|
# get_count = partial(enterprise.get_enterprise_model_and_device_count)
|
|
|
|
|
|
|
|
# futures = [
|
|
|
|
|
|
|
|
# executor.submit(get_count, entity_id=item["id"], entity_suid="")
|
|
|
|
|
|
|
|
# for item in result
|
|
|
|
|
|
|
|
# ]
|
|
|
|
|
|
|
|
# results = [future.result() for future in futures]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# model_counts = [result[0] for result in results]
|
|
|
|
|
|
|
|
# device_counts = [result[1] for result in results]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count_results = await asyncio.gather(
|
|
|
|
|
|
|
|
*[
|
|
|
|
|
|
|
|
enterprise.get_enterprise_model_and_device_count(entity_id=item["id"])
|
|
|
|
|
|
|
|
for item in result
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model_counts = [result[0] for result in count_results]
|
|
|
|
|
|
|
|
device_counts = [result[1] for result in count_results]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = [
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"id": item["id"],
|
|
|
|
"id": item["id"],
|
|
|
|
"name": item["name"],
|
|
|
|
"name": item["name"],
|
|
|
|
"industry": item["industry"],
|
|
|
|
"industry": consts.industry_map[item["industry"]],
|
|
|
|
"modelCount": modelCount,
|
|
|
|
"modelCount": model_count,
|
|
|
|
"deviceCount": deviceCount,
|
|
|
|
"deviceCount": device_count,
|
|
|
|
"logo": item["logo"],
|
|
|
|
"logo": item["logo"],
|
|
|
|
"createTime": str(item["create_time"])
|
|
|
|
"createTime": str(item["create_time"]),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for item, model_count, device_count in zip(
|
|
|
|
|
|
|
|
result, model_counts, device_counts
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
self.finish({"count": count, "data": data})
|
|
|
|
self.finish({"count": count, "data": data})
|
|
|
|
|
|
|
|
|
|
|
@ -96,14 +137,25 @@ class EntityAddHandler(APIHandler):
|
|
|
|
summary = self.get_escaped_argument("summary", "")
|
|
|
|
summary = self.get_escaped_argument("summary", "")
|
|
|
|
logo = self.get_escaped_argument("logo", "")
|
|
|
|
logo = self.get_escaped_argument("logo", "")
|
|
|
|
|
|
|
|
|
|
|
|
if not name or not province or not city or not addr or not industry or not contact or not phone or not summary:
|
|
|
|
if (
|
|
|
|
|
|
|
|
not name
|
|
|
|
|
|
|
|
or not province
|
|
|
|
|
|
|
|
or not city
|
|
|
|
|
|
|
|
or not addr
|
|
|
|
|
|
|
|
or not industry
|
|
|
|
|
|
|
|
or not contact
|
|
|
|
|
|
|
|
or not phone
|
|
|
|
|
|
|
|
or not summary
|
|
|
|
|
|
|
|
):
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数缺失")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数缺失")
|
|
|
|
|
|
|
|
|
|
|
|
if industry not in consts.industry_map:
|
|
|
|
if industry not in consts.industry_map:
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "清选择行业类型")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "清选择行业类型")
|
|
|
|
|
|
|
|
|
|
|
|
if logo and len(logo) * 0.75 / 1024 / 1024 > 1.2:
|
|
|
|
if logo and len(logo) * 0.75 / 1024 / 1024 > 1.2:
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "Logo图标大小超出1M限制")
|
|
|
|
raise errors.HTTPAPIError(
|
|
|
|
|
|
|
|
errors.ERROR_BAD_REQUEST, "Logo图标大小超出1M限制"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
short_uid = shortuuid.ShortUUID().random(length=8)
|
|
|
|
short_uid = shortuuid.ShortUUID().random(length=8)
|
|
|
|
pwd = aes.encrypt(settings.enterprise_aes_key, short_uid)
|
|
|
|
pwd = aes.encrypt(settings.enterprise_aes_key, short_uid)
|
|
|
@ -127,7 +179,7 @@ class EntityAddHandler(APIHandler):
|
|
|
|
"logo": logo,
|
|
|
|
"logo": logo,
|
|
|
|
"account": "admin",
|
|
|
|
"account": "admin",
|
|
|
|
"pwd": pwd,
|
|
|
|
"pwd": pwd,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
conn.commit()
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
|
@ -157,21 +209,31 @@ class EntityEditHandler(APIHandler):
|
|
|
|
logo = self.get_escaped_argument("logo", "")
|
|
|
|
logo = self.get_escaped_argument("logo", "")
|
|
|
|
account = self.get_escaped_argument("account", "")
|
|
|
|
account = self.get_escaped_argument("account", "")
|
|
|
|
|
|
|
|
|
|
|
|
if not name or not province or not city or not addr or not industry or not contact or not phone or not summary:
|
|
|
|
if (
|
|
|
|
|
|
|
|
not name
|
|
|
|
|
|
|
|
or not province
|
|
|
|
|
|
|
|
or not city
|
|
|
|
|
|
|
|
or not addr
|
|
|
|
|
|
|
|
or not industry
|
|
|
|
|
|
|
|
or not contact
|
|
|
|
|
|
|
|
or not phone
|
|
|
|
|
|
|
|
or not summary
|
|
|
|
|
|
|
|
):
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数缺失")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数缺失")
|
|
|
|
|
|
|
|
|
|
|
|
if industry not in consts.industry_map:
|
|
|
|
if industry not in consts.industry_map:
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "清选择行业类型")
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "清选择行业类型")
|
|
|
|
|
|
|
|
|
|
|
|
if logo and len(logo) * 0.75 / 1024 / 1024 > 1.2:
|
|
|
|
if logo and len(logo) * 0.75 / 1024 / 1024 > 1.2:
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "Logo图标大小超出1M限制")
|
|
|
|
raise errors.HTTPAPIError(
|
|
|
|
|
|
|
|
errors.ERROR_BAD_REQUEST, "Logo图标大小超出1M限制"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
conn.execute(
|
|
|
|
conn.execute(
|
|
|
|
text(
|
|
|
|
text(
|
|
|
|
# "insert into enterprise(name, province, city, addr, industry, contact, phone, summary, logo, account, pwd) "
|
|
|
|
# "insert into enterprise(name, province, city, addr, industry, contact, phone, summary, logo, account, pwd) "
|
|
|
|
# "values(:name, :province, :city, :addr, :industry, :contact, :phone, :summary, :logo, :account, :pwd)"
|
|
|
|
# "values(:name, :province, :city, :addr, :industry, :contact, :phone, :summary, :logo, :account, :pwd)"
|
|
|
|
|
|
|
|
|
|
|
|
"update enterprise set name=:name, province=:province, city=:city, addr=:addr, industry=:industry, contact"
|
|
|
|
"update enterprise set name=:name, province=:province, city=:city, addr=:addr, industry=:industry, contact"
|
|
|
|
"=:contact, phone=:phone, summary=:summary, logo=:logo, account=:account where id=:id",
|
|
|
|
"=:contact, phone=:phone, summary=:summary, logo=:logo, account=:account where id=:id",
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -186,7 +248,8 @@ class EntityEditHandler(APIHandler):
|
|
|
|
"summary": summary,
|
|
|
|
"summary": summary,
|
|
|
|
"logo": logo,
|
|
|
|
"logo": logo,
|
|
|
|
"account": account,
|
|
|
|
"account": account,
|
|
|
|
}
|
|
|
|
"id": eid,
|
|
|
|
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
conn.commit()
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
|
@ -222,6 +285,7 @@ class EntityInfoHandler(APIHandler):
|
|
|
|
"name": row["name"],
|
|
|
|
"name": row["name"],
|
|
|
|
"province": row["province"],
|
|
|
|
"province": row["province"],
|
|
|
|
"city": row["city"],
|
|
|
|
"city": row["city"],
|
|
|
|
|
|
|
|
"addr": row["addr"],
|
|
|
|
"industry": row["industry"],
|
|
|
|
"industry": row["industry"],
|
|
|
|
"contact": row["contact"],
|
|
|
|
"contact": row["contact"],
|
|
|
|
"phone": row["phone"],
|
|
|
|
"phone": row["phone"],
|
|
|
@ -242,9 +306,7 @@ class EntityDeleteHandler(APIHandler):
|
|
|
|
eid = self.get_int_argument("id")
|
|
|
|
eid = self.get_int_argument("id")
|
|
|
|
|
|
|
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
conn.execute(
|
|
|
|
conn.execute(text("update enterprise set del=1 where id=:id"), {"id": eid})
|
|
|
|
text("update enterprise set del=1 where id=:id"), {"id": eid}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
|
@ -259,7 +321,9 @@ class EntityPwdcheckHandler(APIHandler):
|
|
|
|
eid = self.get_int_argument("id")
|
|
|
|
eid = self.get_int_argument("id")
|
|
|
|
|
|
|
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
cur = conn.execute(text("select pwd from enterprise where id=:id"), {"id": eid})
|
|
|
|
cur = conn.execute(
|
|
|
|
|
|
|
|
text("select pwd from enterprise where id=:id"), {"id": eid}
|
|
|
|
|
|
|
|
)
|
|
|
|
# row = cur.fetchone()
|
|
|
|
# row = cur.fetchone()
|
|
|
|
logging.info(cur)
|
|
|
|
logging.info(cur)
|
|
|
|
row = db_mysql.to_json(cur)
|
|
|
|
row = db_mysql.to_json(cur)
|
|
|
@ -271,3 +335,9 @@ class EntityPwdcheckHandler(APIHandler):
|
|
|
|
pwd_dcrypt = aes.decrypt(settings.enterprise_aes_key, pwd)
|
|
|
|
pwd_dcrypt = aes.decrypt(settings.enterprise_aes_key, pwd)
|
|
|
|
|
|
|
|
|
|
|
|
self.finish({"pwd": pwd_dcrypt})
|
|
|
|
self.finish({"pwd": pwd_dcrypt})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IndustryMapHandler(APIHandler):
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
|
|
|
def post(self):
|
|
|
|
|
|
|
|
self.finish(consts.industry_map)
|
|
|
|