financialRulesIncrementalGate.js
4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { getStableReconciliationRuleId } from "../../merchantStep/utils/reconciliationIncrementalRules"
import { shouldIncludeReconciliationTabForProcess } from "../../merchantStep/utils/reconciliationSubmitTabGate"
import { reconciliationRulePayloadIsSubstantive } from "../../merchantStep/utils/validateReconciliationRulePayload"
import { financialRulePayloadDeepEqual } from "./rulePayloadCanonicalCompare"
import { prepareRuleForValidation } from "./validateGoodsTypeGroupRulePayload"
/**
* @param {Array<object>|null|undefined} baseline
* @param {number} ti
* @returns {boolean}
*/
export function financialBaselineHasSlotForTabIndex(baseline, ti) {
const prevRaw = Array.isArray(baseline) ? baseline[ti] : null
return !!(prevRaw && typeof prevRaw === "object")
}
/**
* @param {object|null|undefined} baselineRule
* @param {object|null|undefined} currentRule
* @returns {boolean}
*/
export function financialRulePayloadEqualsNormalized(baselineRule, currentRule) {
if (!baselineRule || typeof baselineRule !== "object") {
if (!currentRule || typeof currentRule !== "object") return true
return !reconciliationRulePayloadIsSubstantive(currentRule)
}
if (!currentRule || typeof currentRule !== "object") return true
const curNorm = prepareRuleForValidation(currentRule)
const prevNorm = prepareRuleForValidation(baselineRule)
return financialRulePayloadDeepEqual(curNorm, prevNorm)
}
/**
* 当前 Tab 槽位规则是否与进入页时的基线不一致。
*
* @param {Array<object>|null|undefined} baseline
* @param {number} ti
* @param {object|null|undefined} currentRule
* @returns {boolean}
*/
export function financialTabDiffersFromBaseline(baseline, ti, currentRule) {
if (!Array.isArray(baseline)) return false
const prevRaw = baseline[ti]
if (!prevRaw) {
if (!currentRule) return false
return reconciliationRulePayloadIsSubstantive(currentRule)
}
return !financialRulePayloadEqualsNormalized(prevRaw, currentRule)
}
/**
* 校验通过后的单条规则快照是否与进入页基线一致(用于收缩 goodsTypeGroupRules 增量)。
*
* @param {Array<object>|null|undefined} baseline
* @param {number} ti
* @param {object|null|undefined} snapshot
* @returns {boolean}
*/
export function financialSnapshotEqualsBaseline(baseline, ti, snapshot) {
if (!Array.isArray(baseline) || !snapshot || typeof snapshot !== "object") {
return false
}
const prevRaw = baseline[ti]
if (!prevRaw) {
if (!reconciliationRulePayloadIsSubstantive(snapshot)) return true
return false
}
return financialRulePayloadEqualsNormalized(prevRaw, snapshot)
}
/**
* 全量保存:与 merchantCheck indicesToProcess 同款语义。
* 仅 touched/sessionAdded 且与基线 diff(或无基线槽位)的 Tab 进入增量候选。
*
* @param {Array<object>} editableTabs
* @param {Array<object>|null|undefined} baseline
* @param {Array<object>|null|undefined} slotCaches financialObj.goodsTypeGroupRules
* @returns {number[]}
*/
export function resolveIndicesForFinancialIncrementalSubmit(
editableTabs,
baseline,
slotCaches
) {
const indices = []
const tabs = editableTabs || []
const caches = slotCaches || []
for (let i = 0; i < tabs.length; i++) {
const tab = tabs[i]
if (!tab || String(tab.name) === "add") continue
const differs = financialTabDiffersFromBaseline(baseline, i, caches[i])
const isSessionAdded = tab.sessionAdded === true
if (!differs && !isSessionAdded) continue
if (differs) {
if (
!shouldIncludeReconciliationTabForProcess({
hasBaselineSlot: financialBaselineHasSlotForTabIndex(baseline, i),
classificationUserTouched: tab.classificationUserTouched === true,
sessionAdded: isSessionAdded
})
) {
continue
}
}
indices.push(i)
}
return indices
}
/**
* 校验通过的 Tab 中,仅「快照与基线仍不一致」的进入提交(无基线时仅 sessionAdded 且 substantive)。
*
* @param {number[]} dirtyIndices
* @param {Record<number, object>} validatedByIndex
* @param {Array<object>|null|undefined} baseline
* @param {Array<object>} editableTabs
* @returns {number[]}
*/
export function filterFinancialIndicesToSubmitIncremental(
dirtyIndices,
validatedByIndex,
baseline,
editableTabs
) {
const tabs = editableTabs || []
return (dirtyIndices || []).filter((ti) => {
const rule = validatedByIndex[ti]
if (!rule || typeof rule !== "object") return false
if (!Array.isArray(baseline)) {
return (
tabs[ti]?.sessionAdded === true
&& reconciliationRulePayloadIsSubstantive(rule)
)
}
return !financialSnapshotEqualsBaseline(baseline, ti, rule)
})
}