fix: 设备验收预警优化
This commit is contained in:
1 parent
7e7bcbd388
commit
b8cc0cbe77
25 files changed
+1398
-193
No files matched your search
@@ -1,10 +1,10 @@
|
||||
"""
|
||||
backend/app/services/equipment_acceptance/config_service.py
|
||||
|
||||
用途:读写设备验收预警配置:四档天数和三个固定岗位。
|
||||
用途:读写设备验收预警配置:四档天数、第 4 轮开关和三个固定岗位。
|
||||
依赖:extensions.db、EquipmentAcceptanceSetting、User、统一错误。
|
||||
逻辑:配置页和停留列表调用。岗位只存系统用户主键。发送时刻不在这里,由排程 Cron 决定。
|
||||
没有配置行时按冻结默认值 30/37/44/51 返回,不把姓名写进代码。
|
||||
没有配置行时按冻结默认值 30/37/44/51 返回,第 4 轮默认关闭,不把姓名写进代码。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -29,6 +29,44 @@ _ROLE_FIELDS = (
|
||||
_MAX_DAY = 3650
|
||||
|
||||
|
||||
def is_round_4_enabled() -> bool:
|
||||
"""
|
||||
读取第 4 轮是否启用。
|
||||
|
||||
核心逻辑:没有配置行或字段为假时关闭。关闭后扫描不生成、发送不推出总经理那一轮。
|
||||
Returns:
|
||||
启用为 True。
|
||||
"""
|
||||
row = db.session.get(EquipmentAcceptanceSetting, _SETTING_ID)
|
||||
if row is None:
|
||||
return False
|
||||
return bool(row.round_4_enabled)
|
||||
|
||||
|
||||
def parse_round_4_enabled(raw: Any) -> bool:
|
||||
"""
|
||||
校验第 4 轮开关。
|
||||
|
||||
核心逻辑:缺省按关闭处理,避免旧请求误打开总经理提醒。传入值必须是布尔。
|
||||
Args:
|
||||
raw: 接口里的 round_4_enabled。缺省为 None。
|
||||
Returns:
|
||||
是否启用第 4 轮。
|
||||
|
||||
Raises:
|
||||
ValidationError: 传入了布尔以外的值。
|
||||
"""
|
||||
if raw is None:
|
||||
return False
|
||||
if not isinstance(raw, bool):
|
||||
raise ValidationError(
|
||||
"第 4 轮开关必须是是否启用",
|
||||
code="EQUIPMENT_ACCEPTANCE.SETTINGS_INVALID",
|
||||
details={"field": "round_4_enabled"},
|
||||
)
|
||||
return raw
|
||||
|
||||
|
||||
def reminder_days() -> tuple[int, int, int, int]:
|
||||
"""
|
||||
读取四档天数。
|
||||
@@ -65,12 +103,13 @@ def get_acceptance_config(*, include_candidates: bool) -> dict[str, Any]:
|
||||
Args:
|
||||
include_candidates: 为 True 时附带在职用户,供选人弹窗使用。
|
||||
Returns:
|
||||
days、三个岗位用户主键、已选用户、候选人和更新时间。
|
||||
days、第 4 轮开关、三个岗位用户主键、已选用户、候选人和更新时间。
|
||||
"""
|
||||
row = db.session.get(EquipmentAcceptanceSetting, _SETTING_ID)
|
||||
selected_ids = _selected_ids(row)
|
||||
return {
|
||||
"days": list(_days_of(row)),
|
||||
"round_4_enabled": False if row is None else bool(row.round_4_enabled),
|
||||
"buyer_manager_user_id": None if row is None else row.buyer_manager_user_id,
|
||||
"coo_user_id": None if row is None else row.coo_user_id,
|
||||
"executive_user_id": None if row is None else row.executive_user_id,
|
||||
@@ -82,12 +121,12 @@ def get_acceptance_config(*, include_candidates: bool) -> dict[str, Any]:
|
||||
|
||||
def save_acceptance_config(payload: dict[str, Any], *, updated_by: int) -> dict[str, Any]:
|
||||
"""
|
||||
保存四档天数和三个岗位用户。
|
||||
保存四档天数、第 4 轮开关和三个岗位用户。
|
||||
|
||||
核心逻辑:天数必须逐档增大。岗位为空表示未选;有值时必须是已存在的系统用户。
|
||||
保存后只影响以后的预警,这里不改历史发送记录。
|
||||
核心逻辑:天数必须逐档增大。第 4 轮缺省为关闭。岗位为空表示未选;有值时必须是已存在的系统用户。
|
||||
保存后只影响以后的预警,这里不改历史发送记录。已有的待发送第 4 轮在发送时会被跳过。
|
||||
Args:
|
||||
payload: days 为四个整数;三个岗位字段为用户主键或空。
|
||||
payload: days 为四个整数;round_4_enabled 为布尔;三个岗位字段为用户主键或空。
|
||||
updated_by: 操作人的系统用户主键。
|
||||
Returns:
|
||||
与读取接口相同的配置,并带候选人。
|
||||
@@ -96,12 +135,14 @@ def save_acceptance_config(payload: dict[str, Any], *, updated_by: int) -> dict[
|
||||
ValidationError: 天数不合法,或岗位用户不存在。
|
||||
"""
|
||||
days = validate_reminder_days(payload.get("days"))
|
||||
round_4_enabled = parse_round_4_enabled(payload.get("round_4_enabled"))
|
||||
role_ids = {field: _require_user_id(payload.get(field), field) for field in _ROLE_FIELDS}
|
||||
row = db.session.get(EquipmentAcceptanceSetting, _SETTING_ID)
|
||||
if row is None:
|
||||
row = EquipmentAcceptanceSetting(id=_SETTING_ID)
|
||||
db.session.add(row)
|
||||
row.day_1, row.day_2, row.day_3, row.day_4 = days
|
||||
row.round_4_enabled = round_4_enabled
|
||||
row.buyer_manager_user_id = role_ids["buyer_manager_user_id"]
|
||||
row.coo_user_id = role_ids["coo_user_id"]
|
||||
row.executive_user_id = role_ids["executive_user_id"]
|
||||
|
||||
Reference in new issue
Block a user