unis-oa/sql/upgrade/20261120_reimb_update_month...

62 lines
4.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 2026-11-20 生产配置增量:写回财务数字助手的那一句报销月份照展示那一句念
--
-- 症状:费用报销单发起页上「发票审核」那一格嵌页面打不开,后端留痕
-- embed: reimb_shfp 取嵌入链接失败:取链接的接口回了 400:
-- {"code":400,"message":"reimbursement_date is too long"}(11-20 起共 21 次,
-- 涉及 4 个人)。同一句 400 在写回通道也会撞,只是那条不弹到人脸上。
-- 原因:报销月份(多选)那一格库里存的是数组 ["2026-08","2026-09","2026-10"],
-- 送出去时拼成 27 个字符的一长串,而对方那一栏实测只收 20 个字节——挑到第三个
-- 月就必挂。写回通道 reimb_update 的 payload 里那一格挂的是
-- `",".join(value) ...`(逗号拼),三个月 23 个字节,同样越线。
-- 嵌入页那一头(reimb_shfp)已经改好后端的取参数口径:整串都是月份就交
-- 「2026年8-10月」这一句人话(service/formruntime.py:months_wire_text,
-- 上限 80 个字符),与人在 OA 屏幕上看到的同一句话,挑得越多反而越短。
-- 范围:只改 oa_integration code=reimb_update 的 payload 里 reimbursement_date
-- 那一行的派生值脚本,从逗号拼换成同一口径的 months_wire_text(value)。
-- 后面那半截 or 是兜底的:现网这张格的存值有过 "10"、"10月" 这类老写法,
-- months_wire_text 认不出来会回空串,那种值原样送出去比送空串好。
-- 全表扫过(JSON_SEARCH 找 `{form.reimbursement_date}`),生产上带这一格的写回通道
-- 只有 reimb_update 这一条;财务经理那一环挂的 reimb_update_issh 不带这格,不用改。
-- 执行:**必须在装了这一版代码的镜像上线之后再跑**。这一条挂在发起人环节 cr_begin 的
-- writeback.blocks(trigger=leave)上,是拦住不放行的那一档:SQL 先跑而代码还没上,
-- 沙箱里没有 months_wire_text 这个函数,派生值脚本当场抛「派生值脚本没算出来」,
-- 报销单连发起环节都提交不出去,比"晚一步上线"响得多。反过来先上代码后跑 SQL,
-- 中间那一段写回的仍是逗号拼,行为与今天一模一样,谁都不受影响。
-- 整段可重复跑:中间那句 UPDATE 按路径覆盖同一格,跑几遍存进去的是同一句话;
-- 前后那两句 SELECT 只读,不改一个字节。
-- 回滚:文件末尾注释里那条 UPDATE 跑一遍即可退回逗号拼。
-- 核账:改之前那一行是什么
SELECT JSON_UNQUOTE(JSON_SEARCH(`payload`, 'one', '{form.reimbursement_date}', NULL, '$.fields[*].from')) AS found_at,
JSON_EXTRACT(`payload`,
REPLACE(JSON_UNQUOTE(JSON_SEARCH(`payload`, 'one', '{form.reimbursement_date}', NULL, '$.fields[*].from')), '.from', '.transform')
) AS transform_before
FROM `oa_integration`
WHERE `code` = 'reimb_update';
UPDATE `oa_integration`
SET `payload` = JSON_SET(
`payload`,
REPLACE(JSON_UNQUOTE(JSON_SEARCH(`payload`, 'one', '{form.reimbursement_date}', NULL, '$.fields[*].from')), '.from', '.transform'),
'months_wire_text(value) or (",".join(value) if isinstance(value, list) else str(value or ""))'
)
WHERE `code` = 'reimb_update'
AND JSON_SEARCH(`payload`, 'one', '{form.reimbursement_date}', NULL, '$.fields[*].from') IS NOT NULL;
-- 核账:改完应当只剩这一句,且整份 payload 仍是合法 JSON(JSON_LENGTH 不是 null)
SELECT JSON_EXTRACT(`payload`,
REPLACE(JSON_UNQUOTE(JSON_SEARCH(`payload`, 'one', '{form.reimbursement_date}', NULL, '$.fields[*].from')), '.from', '.transform')
) AS transform_after,
JSON_LENGTH(`payload`) AS payload_keys
FROM `oa_integration`
WHERE `code` = 'reimb_update';
-- 回滚:
-- UPDATE `oa_integration`
-- SET `payload` = JSON_SET(
-- `payload`,
-- REPLACE(JSON_UNQUOTE(JSON_SEARCH(`payload`, 'one', '{form.reimbursement_date}', NULL, '$.fields[*].from')), '.from', '.transform'),
-- '",".join(value) if isinstance(value, list) else str(value or "")'
-- )
-- WHERE `code` = 'reimb_update';