Commit 22325f27 authored by wang.wenrong's avatar wang.wenrong

Merge branch 'wwr' into 'develop'

设备管理复用cid逻辑

See merge request !47
parents 94beaf9a 41a6142d
...@@ -28,9 +28,12 @@ async def get_user_hardware_info(company_id, page_num, page_size): ...@@ -28,9 +28,12 @@ async def get_user_hardware_info(company_id, page_num, page_size):
# 1. 获取总的point数量 # 1. 获取总的point数量
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
point_sql_tmp = "select p.pid, p.name, p.create_time, p.update_time " \ point_sql_tmp = "select p.pid, p.name, p.create_time, p.update_time " \
"from point p inner JOIN monitor c " \ "from monitor c " \
"on p.mtid = c.mtid where p.cid=%s and c.demolished=0" "left join point p on p.mtid = c.mtid " \
points_tmp = await conn.fetchall(sql=point_sql_tmp, args=(company_id,)) "left join monitor_reuse m on m.mtid = c.mtid " \
"where c.demolished=0 " \
"and (p.cid =%s or m.cid = %s) "
points_tmp = await conn.fetchall(sql=point_sql_tmp, args=(company_id,company_id))
point_ids_tmp = [point["pid"] for point in points_tmp] point_ids_tmp = [point["pid"] for point in points_tmp]
# 拆表 # 拆表
point_mid_map_tmp, point_count = await point_to_mid(point_ids_tmp) point_mid_map_tmp, point_count = await point_to_mid(point_ids_tmp)
...@@ -39,7 +42,7 @@ async def get_user_hardware_info(company_id, page_num, page_size): ...@@ -39,7 +42,7 @@ async def get_user_hardware_info(company_id, page_num, page_size):
offset = (page_num - 1) * page_size offset = (page_num - 1) * page_size
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
point_sql = "select pid, name, create_time, update_time, position " \ point_sql = "select pid, name, create_time, update_time, position " \
"from point where cid = %s and pid in %s " \ "from point where cid = %s or pid in %s " \
"limit %s offset %s" "limit %s offset %s"
points = await conn.fetchall(sql=point_sql, args=(company_id, tuple(point_id_tmp), page_size, offset)) points = await conn.fetchall(sql=point_sql, args=(company_id, tuple(point_id_tmp), page_size, offset))
point_ids = [point["pid"] for point in points] point_ids = [point["pid"] for point in points]
...@@ -149,6 +152,10 @@ async def get_user_hardware_info(company_id, page_num, page_size): ...@@ -149,6 +152,10 @@ async def get_user_hardware_info(company_id, page_num, page_size):
data["inline_capacity"] = meter_param["tc"] data["inline_capacity"] = meter_param["tc"]
if not check_value_is_null(meter_param["vc"]): if not check_value_is_null(meter_param["vc"]):
data["rated_voltage"] = meter_param["vc"] data["rated_voltage"] = meter_param["vc"]
if not check_value_is_null(meter_param["bureau_number"]):
data["belong_number"] = meter_param["bureau_number"]
if not check_value_is_null(meter_param["td_type"]):
data["device_type"] = meter_param["td_type"]
datas.append(data) datas.append(data)
return { return {
...@@ -211,17 +218,22 @@ async def hardware_statistics(company_id): ...@@ -211,17 +218,22 @@ async def hardware_statistics(company_id):
# #
# point_count = point_count_map["point_count"] # point_count = point_count_map["point_count"]
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
point_sql = "select p.pid from point p inner JOIN monitor c " \ point_sql = "select p.pid from point p " \
"on p.mtid = c.mtid where p.cid =%s and " \ "left JOIN monitor c on p.mtid = c.mtid " \
"c.demolished=0" "left join monitor_reuse m on c.mtid = m.mtid " \
points = await conn.fetchall(sql=point_sql, args=(company_id,)) "where c.demolished=0 and " \
"(p.cid_belongedto =%s or m.cid=%s)"
points = await conn.fetchall(sql=point_sql,
args=(company_id, company_id))
point_ids = [point["pid"] for point in points] point_ids = [point["pid"] for point in points]
mid_info, point_count = await point_to_mid(point_ids) mid_info, point_count = await point_to_mid(point_ids)
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
inline_sql = "select count(*) as inline_count from inline where " \ inline_sql = "select count(*) as inline_count from inline where " \
"cid = %s" "cid_belongedto = %s"
inline_count_map = await conn.fetchone(sql=inline_sql, args=(company_id,)) inline_count_map = await conn.fetchone(sql=inline_sql,
args=(company_id,))
inline_count = inline_count_map["inline_count"] inline_count = inline_count_map["inline_count"]
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
...@@ -229,12 +241,13 @@ async def hardware_statistics(company_id): ...@@ -229,12 +241,13 @@ async def hardware_statistics(company_id):
create_time_map = await conn.fetchone(sql=time_sql, args=(company_id,)) create_time_map = await conn.fetchone(sql=time_sql, args=(company_id,))
create_time_timestamp = create_time_map["create_time"] create_time_timestamp = create_time_map["create_time"]
start_time = datetime.strftime(datetime.fromtimestamp( start_time = datetime.strftime(
create_time_timestamp), "%Y-%m-%d %H:%M") datetime.fromtimestamp(create_time_timestamp), "%Y-%m-%d %H:%M")
# power_capacity供电容量字段计算错误,改为inline表的tc_runtime字段相加 # power_capacity供电容量字段计算错误,改为inline表的tc_runtime字段相加
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
capacity_sql = "select tc_runtime from inline where cid = %s" capacity_sql = "select tc_runtime from inline where cid_belongedto = %s"
capacity_list = await conn.fetchall(sql=capacity_sql, args=(company_id,)) capacity_list = await conn.fetchall(sql=capacity_sql,
args=(company_id,))
power_capacity = 0 power_capacity = 0
for capacity in capacity_list: for capacity in capacity_list:
if capacity and capacity.get("tc_runtime"): if capacity and capacity.get("tc_runtime"):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment