44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import re
|
|
|
|
|
|
MISC_PROCESS_NAME = "杂活"
|
|
|
|
|
|
def normalize_process_name(value: str | None) -> str:
|
|
text = str(value or "").strip()
|
|
if text == MISC_PROCESS_NAME:
|
|
return MISC_PROCESS_NAME
|
|
if not re.fullmatch(r"\d+", text):
|
|
raise ValueError("工序只能填写正整数,或填写杂活")
|
|
number = int(text)
|
|
if number <= 0:
|
|
raise ValueError("工序只能填写正整数,或填写杂活")
|
|
return str(number)
|
|
|
|
|
|
def normalize_numeric_process_name(value: str | None) -> str:
|
|
text = str(value or "").strip()
|
|
if not re.fullmatch(r"\d+", text):
|
|
raise ValueError("工序必须填写正整数")
|
|
number = int(text)
|
|
if number <= 0:
|
|
raise ValueError("工序必须填写正整数")
|
|
return str(number)
|
|
|
|
|
|
def export_process_name(value: str | None) -> str:
|
|
text = str(value or "").strip()
|
|
if text == MISC_PROCESS_NAME:
|
|
return MISC_PROCESS_NAME
|
|
legacy_match = re.fullmatch(r"0*(\d+)序", text)
|
|
if legacy_match:
|
|
return str(int(legacy_match.group(1)))
|
|
if re.fullmatch(r"\d+", text):
|
|
return str(int(text))
|
|
return text
|
|
|
|
|
|
def process_order(process_name: str | None) -> tuple[int, str]:
|
|
text = export_process_name(process_name)
|
|
return (int(text), text) if re.fullmatch(r"\d+", text) else (0, text)
|