| | |
| | | public static final String MSG_TOO_LONG = "为方便查验附件,附件名字长度不能超过20个字!"; |
| | | public static final String MSG_ILLEGAL = "为方便查验附件,附件名不能包含空格及 / \\ : * ? \" < > | # % 等特殊字符!"; |
| | | public static final String MSG_DUPLICATE = "为方便查验附件,同一行内不能有重名的附件!"; |
| | | /** 2026-11-17:非专家费/伦理专家费的报销单,附件名必须含中文 */ |
| | | public static final String MSG_NEED_CHINESE = |
| | | "附件名不符合医院报销单审批要求:名称须反映发票主要内容(需包含中文),如\"2026年10月住院费\""; |
| | | /** 附件项里取不到任何文件名(既没有 name 也没有 fileName)时的提示 */ |
| | | public static final String MSG_NO_NAME = "为方便查验附件,附件必须带文件名,请重新上传!"; |
| | | |
| | | /** 非法字符:空格(含各类空白)+ / \ : * ? " < > | # % */ |
| | | private static final Pattern ILLEGAL = Pattern.compile("[\\s/\\\\:*?\"<>|#%]"); |
| | | |
| | | /** 中文匹配(主干是否含中文) */ |
| | | private static final Pattern CHINESE = Pattern.compile("[\\u4e00-\\u9fa5]"); |
| | | |
| | | private static final ObjectMapper MAPPER = new ObjectMapper(); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 校验单个文件名。 |
| | | * 校验单个文件名(不要求含中文,兼容旧调用)。 |
| | | * |
| | | * @param fileName 原始文件名 |
| | | * @return {@code null}=通过;否则返回不合格原因 |
| | | */ |
| | | public static String checkName(String fileName) { |
| | | return checkName(fileName, false); |
| | | } |
| | | |
| | | /** |
| | | * 校验单个文件名。 |
| | | * |
| | | * @param fileName 原始文件名 |
| | | * @param requireChinese {@code true}=主干必须含中文(非专家费/伦理专家费的报销单) |
| | | * @return {@code null}=通过;否则返回不合格原因 |
| | | */ |
| | | public static String checkName(String fileName, boolean requireChinese) { |
| | | String name = fileName == null ? "" : fileName.trim(); |
| | | if (name.isEmpty()) { |
| | | return MSG_EMPTY_NAME; |
| | |
| | | return MSG_ILLEGAL; |
| | | } |
| | | String main = mainName(name); |
| | | // 不再强制要求中文;含中文、纯英文、数字均可 |
| | | // 2026-11-17:非专家费/伦理专家费的报销单,附件名主干必须含中文 |
| | | if (requireChinese && !CHINESE.matcher(main).find()) { |
| | | return MSG_NEED_CHINESE; |
| | | } |
| | | // 按字符数计(码点计数:中文/字母/数字/全角各计 1) |
| | | if (main.codePointCount(0, main.length()) > MAX_MAIN_LENGTH) { |
| | | return MSG_TOO_LONG; |
| | |
| | | * @return {@code null}=通过;否则返回不合格原因(含文件名) |
| | | */ |
| | | public static String checkJson(String json) { |
| | | return checkJson(json, null, true); |
| | | return checkJson(json, null, true, false); |
| | | } |
| | | |
| | | /** |
| | | * 校验一个附件列表 JSON(可指定是否必须含中文)。 |
| | | * |
| | | * @param json 附件字段内容(annexfiles / invoicefiles),可为空 |
| | | * @param requireChinese {@code true}=文件名主干必须含中文 |
| | | * @return {@code null}=通过;否则返回不合格原因(含文件名) |
| | | */ |
| | | public static String checkJson(String json, boolean requireChinese) { |
| | | return checkJson(json, null, true, requireChinese); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 需为小写去空白形式;为空/为 null 表示按全新单据处理) |
| | | */ |
| | | public static String checkJsonForUpdate(String json, Set<String> existingNames) { |
| | | return checkJson(json, existingNames, false); |
| | | return checkJson(json, existingNames, false, false); |
| | | } |
| | | |
| | | /** |
| | | * 修改保存时使用(可指定是否必须含中文),忽略"保存前已存在"的历史附件名。 |
| | | */ |
| | | public static String checkJsonForUpdate(String json, Set<String> existingNames, boolean requireChinese) { |
| | | return checkJson(json, existingNames, false, requireChinese); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * @param existingNames 历史附件名(小写),命中则跳过校验;{@code null} 表示不忽略任何名字 |
| | | * @param strictNoName {@code true}=取不到文件名时拦截(全新保存);{@code false}=放行(修改历史单据) |
| | | * @param requireChinese {@code true}=文件名主干必须含中文(非专家费/伦理专家费的报销单) |
| | | */ |
| | | private static String checkJson(String json, Set<String> existingNames, boolean strictNoName) { |
| | | private static String checkJson(String json, Set<String> existingNames, boolean strictNoName, |
| | | boolean requireChinese) { |
| | | if (json == null || json.trim().isEmpty()) { |
| | | return null; |
| | | } |
| | |
| | | // 历史附件(保存前已存在)不参与校验:业务确认"只校验本次变更的附件",避免卡住老单据 |
| | | continue; |
| | | } |
| | | String reason = checkName(name); |
| | | String reason = checkName(name, requireChinese); |
| | | if (reason != null) { |
| | | return "【" + name + "】" + reason; |
| | | } |
| | |
| | | * @param jsons 附件字段内容,可为 null/空 |
| | | * @return {@code null}=通过;否则返回不合格原因 |
| | | */ |
| | | public static String checkJsonList(String... jsons) { if (jsons == null) { |
| | | public static String checkJsonList(String... jsons) { |
| | | return checkJsonList(false, jsons); |
| | | } |
| | | |
| | | /** |
| | | * 校验同一明细行下的多个附件列表(可指定是否必须含中文),逐个列表独立校验: |
| | | * 每个列表内部查重名(与前端 checkDetails 的口径一致)。 |
| | | * |
| | | * @param requireChinese {@code true}=文件名主干必须含中文 |
| | | * @param jsons 附件字段内容,可为 null/空 |
| | | * @return {@code null}=通过;否则返回不合格原因 |
| | | */ |
| | | public static String checkJsonList(boolean requireChinese, String... jsons) { |
| | | if (jsons == null) { |
| | | return null; |
| | | } |
| | | for (String json : jsons) { |
| | | String reason = checkJson(json); |
| | | String reason = checkJson(json, requireChinese); |
| | | if (reason != null) { |
| | | return reason; |
| | | } |
| | |
| | | |
| | | /** 修改保存时使用:忽略历史附件名,逐个列表校验(供"多个字段一起校验"的调用点) */ |
| | | public static String checkJsonListForUpdate(Set<String> existingNames, String... jsons) { |
| | | return checkJsonListForUpdate(existingNames, false, jsons); |
| | | } |
| | | |
| | | /** |
| | | * 修改保存时使用(可指定是否必须含中文):忽略历史附件名,逐个列表校验。 |
| | | */ |
| | | public static String checkJsonListForUpdate(Set<String> existingNames, boolean requireChinese, String... jsons) { |
| | | if (jsons == null) { |
| | | return null; |
| | | } |
| | | for (String json : jsons) { |
| | | String reason = checkJsonForUpdate(json, existingNames); |
| | | String reason = checkJsonForUpdate(json, existingNames, requireChinese); |
| | | if (reason != null) { |
| | | return reason; |
| | | } |