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