Commit cf293000 authored by ZZH's avatar ZZH

add lang switch 2024-05-32

parent cd40d4c2
......@@ -13,6 +13,7 @@ class UserInfoResponse(Model, DbErr, UserErr, JwtErr):
unit: str = Str('单位').eg("汇云中心")
product_list: list = List("产品信息: 1-知电U+, 2-安电U+, 3-安电U+管理版").eg([1, 2, 3])
zhiweiu_auth: int = Int('用户权限:1-普通用户,2-运维用户').eg(1)
lang: str = Str("语言").eg("Chinese")
@dataclass()
......@@ -64,6 +65,7 @@ class UserinfoResp(Model):
unit: str = Str('公司').eg("10086")
job: str = Str('职业').eg("10086")
is_wechat: int = Int('是否绑定微信 1 绑定 0未绑定').eg(1)
lang: str = Str("语言").eg("Chinese")
@dataclass()
......@@ -72,6 +74,7 @@ class UpdateUserInfoReq(Model):
name: str = Opt(Str('姓名').eg("张三"))
unit: str = Opt(Str('公司').eg("10086"))
job: str = Opt(Str('职业').eg("10086"))
lang: str = Opt(Str("语言").eg("Chinese"))
@dataclass()
......
......@@ -82,7 +82,7 @@ async def update_user_is_delete(user_id, wechat_id):
await conn.execute(sql, args=(wechat_id, user_id))
async def search_user_product_auth_dao(user_id):
async def load_user_product_auth(user_id):
sql = "select product,cid_ext,proxy,uassistant_auth" \
" from user_product_auth where user_id = %s "
async with MysqlUtil() as conn:
......
......@@ -75,7 +75,8 @@ async def get_user_info(request) -> UserInfoResponse:
real_name=user_info.get("real_name"),
unit=user_info.get("unit"),
product_list=product_list,
zhiweiu_auth=zhiweiu_auth
zhiweiu_auth=zhiweiu_auth,
lang=user_info["lang"]
)
......@@ -188,7 +189,7 @@ async def post_update_phone(request, body: UpdatePhoneReq):
old_zhiwei_u = phone_info["zhiweiu_auth"]
old_role = phone_info["role"]
wechat_product_auth = await \
search_user_product_auth_dao(phone_info["user_id"])
load_user_product_auth(phone_info["user_id"])
wechat_product_auth_dict = \
{wechat_product["product"]: wechat_product["cid_ext"]
for wechat_product in wechat_product_auth} \
......@@ -202,7 +203,7 @@ async def post_update_phone(request, body: UpdatePhoneReq):
if not auth_verify:
return success_res(code=RET.verify_error, msg="验证码不一致")
user_product_auth = await search_user_product_auth_dao(user_id)
user_product_auth = await load_user_product_auth(user_id)
user_product_auth_dict = \
{user_product["product"]: user_product["cid_ext"]
for user_product in user_product_auth} if user_product_auth else {}
......@@ -232,11 +233,13 @@ async def post_update_phone(request, body: UpdatePhoneReq):
for key, value in product_auth.items():
is_auth = await search_product_auth_dao(user_id, key)
if is_auth:
await update_product_auth_dao(key, value, user_id,
proxy=user_product_dict.get(key) or wechat_product_dict.get(key))
proxy = user_product_dict.get(key) or wechat_product_dict.get(
key)
await update_product_auth_dao(key, value, user_id, proxy=proxy)
else:
await insert_product_auth_dao(user_id, key, value,
proxy=(user_product_dict.get(key) or wechat_product_dict.get(key)))
proxy = (user_product_dict.get(key) or wechat_product_dict.get(
key))
await insert_product_auth_dao(user_id, key, value, proxy=proxy)
return success_res(msg="修改成功")
......@@ -281,7 +284,8 @@ async def post_userinfo(request, body: UserinfoReq) -> UserinfoResp:
is_wechat = 1 if data["wechat_id"] else 0
return UserinfoResp(user_id=data["user_id"], phone=data["phone_number"],
unit=data.get("unit") or "", job=data.get("job") or "",
name=data.get("real_name") or "", is_wechat=is_wechat)
name=data.get("real_name") or "", is_wechat=is_wechat,
lang=data["lang"])
@summary("修改个人信息")
......@@ -291,18 +295,22 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
name = body.name
unit = body.unit
job = body.job
if not any([name, unit, job]):
lang = body.lang
if not any([name, unit, job, lang]):
return success_res(code=RET.params_loss, msg="缺少参数")
if name:
await update_userinfo_dao(user_id, 'real_name', name)
elif unit:
await update_userinfo_dao(user_id, 'unit', unit)
elif lang:
await update_userinfo_dao(user_id, "lang", lang)
else:
await update_userinfo_dao(user_id, 'job', job)
data = await user_by_user_id(user_id)
is_wechat = 1 if data["wechat_id"] else 0
return UserinfoResp(user_id=data["user_id"], phone=data["phone_number"],
unit=data["unit"], job=data["job"],
unit=data["unit"], job=data["job"], lang=data["lang"],
name=data["real_name"], is_wechat=is_wechat)
......@@ -328,6 +336,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
if token_status != 200:
log.error("post_update_wechat get access_token fail")
return success_res(code=RET.wechat_error, msg="微信绑定失败")
result = json.loads(res_token)
# 2.获取用户信息
if 'access_token' not in result:
......@@ -340,6 +349,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
if user_info_status != 200:
log.error("post_update_wechat get user info fail")
return success_res(code=RET.wechat_error, msg="微信绑定失败")
user_info = json.loads(res)
wechat_product_dict, old_zhiwei_u, old_role = {}, None, None
if 'openid' in user_info and 'unionid' in user_info:
......@@ -363,7 +373,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
# await update_not_phone(user_id, unionid)
# 修改权限
wechat_product_auth = await \
search_user_product_auth_dao(data["user_id"])
load_user_product_auth(data["user_id"])
wechat_product_auth_dict = \
{wechat_product["product"]: wechat_product["cid_ext"]
for wechat_product in wechat_product_auth} \
......@@ -372,7 +382,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
{wechat_product["product"]: wechat_product["proxy"]
for wechat_product in wechat_product_auth} \
if wechat_product_auth else {}
user_product_auth = await search_user_product_auth_dao(user_id)
user_product_auth = await load_user_product_auth(user_id)
user_product_auth_dict = \
{user_product["product"]: user_product["cid_ext"]
for user_product in user_product_auth} \
......@@ -401,13 +411,13 @@ async def post_update_wechat(request, body: UpdateWechatReq):
# 修改权限
if product_auth:
for key, value in product_auth.items():
proxy = user_product_dict.get(key) or wechat_product_dict.get(
key)
is_auth = await search_product_auth_dao(user_id, key)
if is_auth:
await update_product_auth_dao(key, value, user_id,
proxy=user_product_dict.get(key) or wechat_product_dict.get(key))
await update_product_auth_dao(key, value, user_id, proxy)
else:
await insert_product_auth_dao(user_id, key, value,
proxy=user_product_dict.get(key) or wechat_product_dict.get(key))
await insert_product_auth_dao(user_id, key, value, proxy)
log.info(f"post_update_wechat product_auth:{product_auth}")
return success_res(msg="微信绑定成功")
return success_res(code=RET.wechat_error, msg="微信绑定失败")
......
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