Commit 6aff3dca authored by wang.wenrong's avatar wang.wenrong

cid修改

parent e49a7c87
......@@ -416,7 +416,7 @@ async def zdu_alarm_aggs_date_impotent(cid, start, end):
return es_result["aggregations"]["date_day"]["buckets"]
async def sdu_alarm_aggs_date_importance(cid):
async def sdu_alarm_aggs_date_importance(cid): # todo: 扬尘es待改
"""按日期,再按等级聚合"""
query_body = {
"size": 0,
......
......@@ -146,7 +146,7 @@ async def change_sensor_by_location(location_id):
async def tsp_by_cid(cid):
"""根据cid查询points"""
sql = "SELECT tsp_id, name FROM tsp WHERE cid_belongedto = %s " \
sql = "SELECT tsp_id, name FROM tsp WHERE cid = %s " \
"order by name"
async with MysqlUtil() as conn:
tsp_list = await conn.fetchall(sql, args=(cid,))
......@@ -212,7 +212,7 @@ async def inline_zdu_all_by_cid(cid):
async def water_by_cid(cid):
sql = "SELECT * FROM water WHERE cid_belongedto = %s"
sql = "SELECT * FROM water WHERE cid = %s"
async with MysqlUtil() as conn:
water_list = await conn.fetchall(sql, args=(cid,))
return water_list
......
......@@ -14,7 +14,7 @@ async def inline_zdu_by_cid(cid):
async def feeder_by_cid(cid):
"""馈线"""
sql = "SELECT * from feeder f inner join monitor m2 " \
"on f.mtid = m2.mtid where f.cid_belongedto = %s " \
"on f.mtid = m2.mtid where f.cid = %s " \
"order by f.sort_num"
async with MysqlUtil() as conn:
feeder_list = await conn.fetchall(sql, args=(cid,))
......@@ -24,7 +24,7 @@ async def feeder_by_cid(cid):
async def transformer_by_cid(cid):
"""变压器"""
sql = "SELECT * from transformer t inner join monitor m2 " \
"on t.mtid = m2.mtid where t.cid_belongedto = %s " \
"on t.mtid = m2.mtid where t.cid = %s " \
"order by t.sort_num"
async with MysqlUtil() as conn:
transformer_list = await conn.fetchall(sql, args=(cid,))
......@@ -34,7 +34,7 @@ async def transformer_by_cid(cid):
async def power_dist_by_cid(cid):
"""配电"""
sql = "SELECT * from power_dist pd inner join monitor m2 " \
"on pd.mtid = m2.mtid where pd.cid_belongedto = %s " \
"on pd.mtid = m2.mtid where pd.cid = %s " \
"order by pd.sort_num"
async with MysqlUtil() as conn:
power_dist_list = await conn.fetchall(sql, args=(cid,))
......@@ -44,7 +44,7 @@ async def power_dist_by_cid(cid):
async def device_level_by_cid(cid):
"""设备级"""
sql = "SELECT * from device_level dl inner join monitor m2 " \
"on dl.mtid = m2.mtid where dl.cid_belongedto = %s " \
"on dl.mtid = m2.mtid where dl.cid = %s " \
"order by dl.sort_num"
async with MysqlUtil() as conn:
device_list = await conn.fetchall(sql, args=(cid,))
......
......@@ -15,12 +15,12 @@ async def get_points(company_ids):
company_point_map = defaultdict(dict)
async with MysqlUtil() as conn:
point_sql = (
"select pid, cid cid_belongedto, inlid from point where cid in %s"
"select pid, cid cid, inlid from point where cid in %s"
)
points = await conn.fetchall(point_sql, args=(company_ids,))
company_point_ids_map = defaultdict(list)
for point in points:
company_point_ids_map[point["cid_belongedto"]].append(point["pid"])
company_point_ids_map[point["cid"]].append(point["pid"])
point_map = {i["pid"]: i for i in points}
point_ids = list(point_map.keys())
......@@ -114,7 +114,7 @@ async def list_point(cid):
list_point = []
points = {}
groups = {}
sql = "SELECT pid, name, add_to_company FROM point WHERE cid_belongedto=%s"
sql = "SELECT pid, name, add_to_company FROM point WHERE cid=%s"
async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(cid,))
for res in result:
......@@ -146,7 +146,7 @@ async def list_point(cid):
list_point.append(comm_point)
async with MysqlUtil() as conn:
sql = "SELECT inlid, `name` FROM inline WHERE cid_belongedto=%s"
sql = "SELECT inlid, `name` FROM inline WHERE cid=%s"
inlines = await conn.fetchall(sql, args=(cid,))
inline_list = [Inline(inline_id=inline["inlid"], name=inline["name"])
for inline in inlines]
......
......@@ -9,7 +9,7 @@ from unify_api.utils.time_format import power_slots, range_to_type
async def pttl_max(cid, start, end, point_id=None, inline_id=None):
# 根据进线,找point
if inline_id:
sql = "SELECT pid from `point` WHERE cid_belongedto = %s " \
sql = "SELECT pid from `point` WHERE cid = %s " \
"and inlid_belongedto = %s and add_to_company = 1"
async with MysqlUtil() as conn:
point_info = await conn.fetchall(sql=sql,
......@@ -18,7 +18,7 @@ async def pttl_max(cid, start, end, point_id=None, inline_id=None):
terms = {"pid": point_list}
elif point_id == -1: # 选的全部
# 1.找出工厂所有pid,point表add_to_company字段为1
sql = "SELECT pid from `point` WHERE cid_belongedto = %s " \
sql = "SELECT pid from `point` WHERE cid = %s " \
"and add_to_company = 1"
async with MysqlUtil() as conn:
point_info = await conn.fetchall(sql=sql, args=(cid,))
......@@ -144,7 +144,7 @@ async def pttl_max_15min(cid, start, end, point_id=None, inline_id=None):
"""负荷分布,最高负荷需要拿15min"""
# 根据进线,找point
if inline_id:
sql = "SELECT pid from `point` WHERE cid_belongedto = %s " \
sql = "SELECT pid from `point` WHERE cid = %s " \
"and inlid_belongedto = %s"
async with MysqlUtil() as conn:
point_info = await conn.fetchall(sql=sql,
......@@ -153,7 +153,7 @@ async def pttl_max_15min(cid, start, end, point_id=None, inline_id=None):
terms = {"pid": point_list}
elif point_id == -1: # 选的全部
# 1.找出工厂所有pid,point表add_to_company字段为1
sql = "SELECT pid from `point` WHERE cid_belongedto = %s"
sql = "SELECT pid from `point` WHERE cid = %s"
async with MysqlUtil() as conn:
point_info = await conn.fetchall(sql=sql, args=(cid,))
point_list = [point.get("pid") for point in point_info]
......
......@@ -62,7 +62,7 @@ async def inset_algorithm_power_factor_dao(inline_id, start_time, std_cos):
async def get_algorithm_power_factor_dao(cid):
sql = "select a.std_cos from algo_power_factor a " \
"LEFT JOIN inline_zdu line on line.inlid =a.inlid " \
"WHERE line.cid_belongedto = %s ORDER BY a.start_time desc limit 1"
"WHERE line.cid = %s ORDER BY a.start_time desc limit 1"
async with MysqlUtil() as conn:
datas = await conn.fetchone(sql, args=(cid,))
return datas
......
......@@ -587,7 +587,7 @@ async def get_power_company_download(req):
# 参数为point_id, 转换为point_list
if point_id == -1: # 选的全部
# 1.找出工厂所有pid,point表add_to_company字段为1
sql = "SELECT pid from `point` WHERE cid_belongedto = %s "
sql = "SELECT pid from `point` WHERE cid = %s "
async with MysqlUtil() as conn:
point_info = await conn.fetchall(sql=sql, args=(cid,))
point_list = [point.get("pid") for point in point_info]
......
......@@ -3,7 +3,7 @@ from pot_libs.mysql_util.mysql_util import MysqlUtil
async def tc_by_inline_id(inline_id):
async with MysqlUtil() as conn:
sql = "select inlid, tc_runtime, cid cid_belongedto" \
sql = "select inlid, tc_runtime, cid cid" \
" from inline where inlid=%s;"
inline = await conn.fetchone(sql, args=(inline_id,))
return inline
......
......@@ -6,13 +6,13 @@ from unify_api.modules.common.procedures.power_cps import \
async def get_inline_datas_dao(cids):
inline_sql = f"select `inlid`, `name`, cid cid_belongedto, " \
inline_sql = f"select `inlid`, `name`, cid cid, " \
f"`inline_tc`, `tc_runtime` from `inline` " \
f"where cid in %s order by cid"
async with MysqlUtil() as conn:
inlines = await conn.fetchall(inline_sql, args=(cids,)) if cids else []
inline_map = {i["inlid"]: i for i in inlines}
inline_cid_map = {i["inlid"]: i["cid_belongedto"] for i in inlines}
inline_cid_map = {i["inlid"]: i["cid"] for i in inlines}
return inline_map, inline_cid_map
......@@ -246,12 +246,12 @@ async def proxy_power_save_list(
cids, month_str, page_size=10, page_num=1, sort_field="company_name", sort_direction="asc",
):
async with MysqlUtil() as conn:
inline_sql = f"select `inlid`, `name`,cid cid_belongedto, " \
inline_sql = f"select `inlid`, `name`,cid cid, " \
f"`inline_tc`, `tc_runtime` from `inline` " \
f"where cid in %s order by cid"
inlines = await conn.fetchall(inline_sql, args=(cids,)) if cids else []
inline_map = {i["inlid"]: i for i in inlines}
inline_cid_map = {i["inlid"]: i["cid_belongedto"] for i in inlines}
inline_cid_map = {i["inlid"]: i["cid"] for i in inlines}
company_map = await get_cid_info(cids)
......@@ -293,7 +293,7 @@ async def proxy_power_save_summary(
if not inline_map:
# 为了代码复用,减少数据库查询,如果外部传了进线信息,那么没必要再查询了
async with MysqlUtil() as conn:
inline_sql = f"select `inlid`, `name`, cid `cid_belongedto`, " \
inline_sql = f"select `inlid`, `name`, cid `cid`, " \
f"`inline_tc`, `tc_runtime` from `inline` " \
f"where cid in %s order by cid"
inlines = await conn.fetchall(inline_sql, args=(cids,)) if cids else []
......@@ -470,7 +470,7 @@ async def proxy_pcvf_summary(
async def proxy_electric_optimization_summary(cids, month_str):
inline_sql = f"select inlid,name,cid cid_belongedto,inline_tc,tc_runtime" \
inline_sql = f"select inlid,name,cid cid,inline_tc,tc_runtime" \
f" from inline where `cid` in %s order by cid"
async with MysqlUtil() as conn:
inlines = await conn.fetchall(inline_sql, args=(cids,)) if cids else []
......
......@@ -30,7 +30,7 @@ async def md_space_service(inline_id):
latest_12_months]
md_space_map = await month_md_space(inline_id, monthstr_list)
inline = await tc_by_inline_id(inline_id)
price_policy = await price_policy_by_cid(inline["cid_belongedto"])
price_policy = await price_policy_by_cid(inline["cid"])
last_month = monthstr_list[-1]
return MdSpaceResp(
......@@ -83,7 +83,7 @@ async def power_factor_service(inline_id):
# 功率因数大于0.9不返回save_charge
save_charge = None
inline = await tc_by_inline_id(inline_id)
point_list = await pids_by_cid(inline.get("cid_belongedto"))
point_list = await pids_by_cid(inline.get("cid"))
charge_res = await point_aggs_kwh_new15(point_list)
# total_charge = charge_res["aggregations"]["charge"]["value"]
total_charge = charge_res.get("charge") or 0
......@@ -152,7 +152,7 @@ async def power_peakcut_service(inline_id):
save_charge = power_pcvf_map.get(str(last_month), {}).get("cost_save")
inline = await tc_by_inline_id(inline_id)
price_policy = await price_policy_by_cid(inline["cid_belongedto"])
price_policy = await price_policy_by_cid(inline["cid"])
if avg_price and price_policy["price_f"]:
growth_percentage = round(
(
......
......@@ -36,7 +36,7 @@ class EnergyStoreOptimize(object):
rlt = {'rlt_flag': True}
inl_info = await self._get_inline_info()
inline_vc = inl_info['inline_vc']
cid = inl_info['cid_belongedto']
cid = inl_info['cid']
pp = await self._get_company_price_policy(cid)
max_dt = await self._find_kwh_max_day() # 00:00:00 of the max kwh day
if not max_dt:
......@@ -124,18 +124,18 @@ class EnergyStoreOptimize(object):
return section
async def _get_inline_info(self):
""" get inline_vc, tc_runtime, cid_belongedto from redis.
""" get inline_vc, tc_runtime, cid from redis.
:return: a dict
"""
# inline_j = self._r_cache.hget(INLINE_HASHNAME, str(self._inlid))
# info = json.loads(inline_j)
sql = "SELECT inline_vc, tc_runtime, cid cid_belongedto from " \
sql = "SELECT inline_vc, tc_runtime, cid cid from " \
"inline where inlid = %s"
async with MysqlUtil() as conn:
info = await conn.fetchone(sql, args=(self._inlid,))
rlt = {'inline_vc': info['inline_vc'],
'tc_runtime': info['tc_runtime'],
'cid_belongedto': info['cid_belongedto']}
'cid': info['cid']}
return rlt
async def _get_company_price_policy(self, cid):
......@@ -310,10 +310,10 @@ class EnergyStoreOptimize(object):
async def ess_out_result(inlid, ess_system):
"""结果输出函数"""
# get cid
sql = "select cid cid_belongedto from inline where inlid = %s"
sql = "select cid cid from inline where inlid = %s"
async with MysqlUtil() as conn:
cid_info = await conn.fetchone(sql=sql, args=(inlid,))
cid = cid_info.get("cid_belongedto")
cid = cid_info.get("cid")
# get proxy_id
sql = "select cpm.proxy from company c inner join company_proxy_map cpm " \
"on cpm.cid=c.cid where c.cid = %s"
......
......@@ -26,7 +26,7 @@ class PhotovoltaicOptimize(object):
rlt = {'rlt_flag': True}
inl_info = await self._get_inline_info()
inline_vc = inl_info['inline_vc']
cid = inl_info['cid_belongedto']
cid = inl_info['cid']
city = await self._get_company_city(cid)
df_pv = await self._construct_pv_curve(city) # construct df_pv
......@@ -376,16 +376,16 @@ class PhotovoltaicOptimize(object):
return df
async def _get_inline_info(self):
""" get inline_vc, tc_runtime, cid_belongedto from redis.
""" get inline_vc, tc_runtime, cid from redis.
:return: a dict
"""
sql = "SELECT inline_vc, tc_runtime, cid cid_belongedto from " \
sql = "SELECT inline_vc, tc_runtime, cid cid from " \
"inline where inlid = %s"
async with MysqlUtil() as conn:
info = await conn.fetchone(sql, args=(self._inlid,))
rlt = {'inline_vc': info['inline_vc'],
'tc_runtime': info['tc_runtime'],
'cid_belongedto': info['cid_belongedto']}
'cid': info['cid']}
return rlt
async def _get_company_price_policy(self, cid):
......
......@@ -552,7 +552,7 @@ async def current_load(company_id):
:return:
"""
async with MysqlUtil() as conn:
point_sql = "select pid from point where cid_belongedto= %s " \
point_sql = "select pid from point where cid= %s " \
"and add_to_company = 1"
points = await conn.fetchall(point_sql, args=(company_id,))
point_ids = [p["pid"] for p in points]
......@@ -855,7 +855,7 @@ async def power_factor(company_id):
"""
async with MysqlUtil() as conn:
point_sql = (
"select pid, inlid_belongedto from point where cid_belongedto= %s and add_to_company=%s"
"select pid, inlid_belongedto from point where cid= %s and add_to_company=%s"
)
points = await conn.fetchall(point_sql, args=(company_id, 1))
point_ids = [i["pid"] for i in points]
......
......@@ -196,7 +196,7 @@ async def hardware_statistics(company_id):
:return:
"""
# async with MysqlUtil() as conn:
# point_sql = "select count(*) as point_count from point where cid_belongedto = %s"
# point_sql = "select count(*) as point_count from point where cid = %s"
# point_count_map = await conn.fetchone(sql=point_sql, args=(company_id,))
#
# point_count = point_count_map["point_count"]
......
......@@ -276,11 +276,11 @@ async def algorithm_result_to_front(point_id, req_date, user_id, product, detail
# 根据配置扩展模块取不同的算法结果字段
async with MysqlUtil() as conn:
point_sql = "select pid, cid_belongedto from point where pid=%s"
point_sql = "select pid, cid from point where pid=%s"
point_map = await conn.fetchone(point_sql, args=(point_id,))
if not point_map:
raise BusinessException(message="没有该监测点的信息,请联系运维人员!")
cid = point_map["cid_belongedto"]
cid = point_map["cid"]
# 2.调用函数获取到用户信息
product_auth_map = await get_product_auth(user_id, product)
cid_ext_module_map = product_auth_map["product"]
......
......@@ -273,7 +273,7 @@ async def tsp_by_tsp_id_dao(start, end, tsp_list):
return datas
async def tsp_histogram_day_tsp_id(interval):
async def tsp_histogram_day_tsp_id(interval): # todo: 扬尘es 待改
"""空气优-按天聚合, 再按tsp_id聚合"""
query_body = {
"size": 0,
......
......@@ -44,7 +44,7 @@ async def get_contrast_data_month_dao(tsp_id, start, end):
async def get_index_data_dao():
sql = "SELECT DISTINCT c.cid, c.shortname, c.fullname, c.industry, " \
"c.province FROM tsp t LEFT JOIN company c on t.cid_belongedto=c.cid"
"c.province FROM tsp t LEFT JOIN company c on t.cid=c.cid"
async with MysqlUtil() as conn:
companys = await conn.fetchall(sql)
return companys
......@@ -59,8 +59,8 @@ async def get_position_dao(company_list):
async def get_tsp_id_list_dao(company_list):
sql = "select cid_belongedto cid,group_concat(tsp_id) tsp_ids from tsp " \
"WHERE cid_belongedto in %s GROUP BY cid_belongedto"
sql = "select cid cid,group_concat(tsp_id) tsp_ids from tsp " \
"WHERE cid in %s GROUP BY cid"
async with MysqlUtil() as conn:
data = await conn.fetchall(sql, args=(company_list,))
return data
......
......@@ -80,7 +80,7 @@ async def get_residual_current_threhold(location_id,
async def get_name_by_pid(pid):
sql = "SELECT c.shortname,p.name FROM `point` p LEFT JOIN company c " \
"on c.cid=p.cid_belongedto where p.pid=%s"
"on c.cid=p.cid where p.pid=%s"
async with MysqlUtil() as conn:
data = await conn.fetchone(sql, args=(pid,))
return data
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