Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-boutique-work-wechat
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9beda67d
authored
Aug 10, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: add store daily save safeguards
1 parent
5be0394a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
207 additions
and
19 deletions
packageDynamicForm/api/storeDailyReport.js
packageDynamicForm/tests/store-daily-save-guards.test.mjs
packageDynamicForm/tests/store-daily-submit-confirm.test.mjs
packageDynamicForm/tests/storeDailyReportDetail.test.mjs
packageDynamicForm/utils/store-daily-save-guards.js
packageDynamicForm/utils/store-daily-submit-confirm.js
packageDynamicForm/api/storeDailyReport.js
View file @
9beda67
...
...
@@ -43,6 +43,7 @@ const {
normalizeMonthlyPendingCountResponse
}
=
require
(
'./storeDailyReportAdapters.js'
)
const
{
normalizeReportStatus
}
=
require
(
'../utils/report-status.js'
)
const
{
resolveDetailRevisionToken
}
=
require
(
'../utils/store-daily-save-guards.js'
)
const
{
normalizeSubmissionStatus
,
formatSubmissionDate
...
...
@@ -361,6 +362,7 @@ function normalizeDetailResponse(detail = {}, reportTemplateId) {
data
:
{
reportTemplateId
:
detail
.
reportTemplateId
||
reportTemplateId
||
STORE_DEFAULT_REPORT_TEMPLATE_ID
,
dailyReportRecordId
:
recordId
,
revisionToken
:
resolveDetailRevisionToken
(
detail
),
baseSceneCode
:
detail
.
baseSceneCode
,
reportStatus
:
normalizeReportStatus
(
detail
.
reportStatus
),
submissionStatus
:
normalizeSubmissionStatus
(
detail
.
submissionStatus
),
...
...
packageDynamicForm/tests/store-daily-save-guards.test.mjs
0 → 100644
View file @
9beda67
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
findDuplicateStoreDailyPhoneRows,
buildStoreDailySaveThrottleKey,
isStoreDailySaveThrottled,
resolveDetailRevisionToken,
hasStoreDailyRevisionConflict
} = require('../utils/store-daily-save-guards.js')
describe('store-daily-save-guards', () => {
it('IT-STORE-SAVE-GUARD-001: returns every row number that shares a non-empty customer phone', () => {
assert.deepEqual(
findDuplicateStoreDailyPhoneRows({
'F2-107': [
{ 'F2-107-2': '13800138000' },
{ 'F2-107-2': '' },
{ 'F2-107-2': ' 13800138000 ' },
{ 'F2-107-2': '13900139000' }
]
}),
[1, 3]
)
})
it('IT-STORE-SAVE-GUARD-002: blocks saves for the first minute after a prior save', () => {
assert.equal(isStoreDailySaveThrottled(1_000, 60_999), true)
assert.equal(isStoreDailySaveThrottled(1_000, 61_000), false)
})
it('IT-STORE-SAVE-GUARD-003: scopes the save throttle key to merchant, report date and staff UUID', () => {
const key = buildStoreDailySaveThrottleKey({
merchantId: 'merchant-001',
reportDate: '2026-08-10',
staffUuid: 'staff-001'
})
assert.match(key, /merchant-001/)
assert.match(key, /2026-08-10/)
assert.match(key, /staff-001/)
})
it('IT-STORE-SAVE-GUARD-004: reports a conflict only when two revision tokens differ', () => {
assert.equal(hasStoreDailyRevisionConflict('revision:1', 'revision:2'), true)
assert.equal(hasStoreDailyRevisionConflict('revision:1', 'revision:1'), false)
})
it('IT-STORE-SAVE-GUARD-005: fingerprints content when no explicit revision field exists', () => {
const first = resolveDetailRevisionToken({ id: 99, jsonContent: '{"sales":1}' })
const second = resolveDetailRevisionToken({ id: 99, jsonContent: '{"sales":2}' })
assert.notEqual(first, second)
})
it('IT-STORE-SAVE-GUARD-006: falls back safely when a detail has no revision or content', () => {
assert.match(resolveDetailRevisionToken({ id: 99 }), /^content:/)
})
})
packageDynamicForm/tests/store-daily-submit-confirm.test.mjs
View file @
9beda67
...
...
@@ -3,17 +3,38 @@ import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const { buildStoreDailySubmitConfirmModal } = require('../utils/store-daily-submit-confirm.js')
const {
buildStoreDailySubmitConfirmModal,
buildStoreDailyConflictModal,
buildStoreDailyLeaveModal
} = require('../utils/store-daily-submit-confirm.js')
describe('store-daily-submit-confirm', () => {
it('IT-STORE-SUBMIT-MODAL-001: report modal copy matches product spec', () => {
const modal = buildStoreDailySubmitConfirmModal()
assert.equal(modal.title, '确定上报门店日报?')
assert.equal(
modal.content,
'请确认驻店人员在当前场景下已完成所有个人的驻店日报及洽谈明细。门店日报上报后,将立即发送相关门店经营统计数据到指定消息群。'
)
assert.equal(modal.cancelText, '我再想想')
assert.equal(modal.confirmText, '确定上报')
assert.deepEqual(buildStoreDailySubmitConfirmModal(), {
title: '确定上报数据?',
content:
'请确认已记录今日所有非成交客户信息,并确保成交客户已完成录单。门店日报上报后,将立即发送相关门店经营统计数据到指定消息群。',
cancelText: '我再想想',
confirmText: '确定'
})
})
it('IT-STORE-SUBMIT-MODAL-002: conflict modal copy warns before overwriting another save', () => {
assert.deepEqual(buildStoreDailyConflictModal(), {
title: '数据已被他人更新',
content: '在你编辑期间,其他用户已完成保存操作。若直接保存,将覆盖对方的最新修改。',
cancelText: '取消',
confirmText: '直接保存'
})
})
it('IT-STORE-SUBMIT-MODAL-003: leave modal copy keeps the user in editing by default', () => {
assert.deepEqual(buildStoreDailyLeaveModal(), {
title: '重要提示',
content: '内容尚未提交,是否退出编辑?',
cancelText: '继续编辑',
confirmText: '确定退出'
})
})
})
packageDynamicForm/tests/storeDailyReportDetail.test.mjs
View file @
9beda67
...
...
@@ -9,6 +9,7 @@ const {
} = await import('../form-engine/submit-adapter.js')
const { createFormEngine } = await import('../form-engine/core.js')
const { isReportSubmitted, normalizeReportStatus } = require('../utils/report-status.js')
const { resolveDetailRevisionToken } = require('../utils/store-daily-save-guards.js')
const { DEFAULT_REPORT_TEMPLATE_ID } = require('../api/mockStoreDynamicDetail.js')
const { loadSchemaFixture } = await import('./schemaFixture.mjs')
...
...
@@ -27,6 +28,7 @@ function normalizeDetailResponse(detail = {}, reportTemplateId) {
dailyReportRecordId: recordId,
baseSceneCode: detail.baseSceneCode,
reportStatus: normalizeReportStatus(detail.reportStatus),
revisionToken: resolveDetailRevisionToken(detail),
values: parseJsonContentDetailValues(jsonContent, []),
jsonContent
}
...
...
@@ -55,6 +57,16 @@ describe('storeDailyReport detail response', () => {
assert.equal(data.reportTemplateId, DEFAULT_REPORT_TEMPLATE_ID)
})
it('IT-STORE-DETAIL-007: normalized details expose the explicit revision token', () => {
const normalized = normalizeDetailResponse({
id: 99,
revisionId: 'rev-2',
jsonContent: '{}'
})
assert.equal(normalized.dailyReportRecordId, 99)
assert.equal(normalized.revisionToken, 'revision:rev-2')
})
it('IT-STORE-DETAIL-004: F2-1 echoes from jsonContent through schema merge and engine init', () => {
const storeSchema = loadSchemaFixture('store')
const detail = normalizeDetailResponse({
...
...
packageDynamicForm/utils/store-daily-save-guards.js
0 → 100644
View file @
9beda67
const
STORE_DAILY_SAVE_THROTTLE_MS
=
60
_000
function
stableSerialize
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
`[
${
value
.
map
(
stableSerialize
).
join
(
','
)}
]`
}
if
(
value
&&
typeof
value
===
'object'
)
{
return
`{
${
Object
.
keys
(
value
)
.
sort
()
.
map
(
key
=>
`
${
JSON
.
stringify
(
key
)}
:
${
stableSerialize
(
value
[
key
])}
`
)
.
join
(
','
)}
}`
}
return
JSON
.
stringify
(
value
)
??
'null'
}
function
fingerprint
(
value
)
{
let
hash
=
0
for
(
let
index
=
0
;
index
<
value
.
length
;
index
+=
1
)
{
hash
=
(
hash
*
31
+
value
.
charCodeAt
(
index
))
|
0
}
return
`
${(
hash
>>>
0
).
toString
(
16
)}
:
${
value
.
length
}
`
}
function
normalizeJsonContent
(
jsonContent
)
{
if
(
typeof
jsonContent
!==
'string'
)
{
return
jsonContent
}
try
{
return
JSON
.
parse
(
jsonContent
)
}
catch
(
error
)
{
return
jsonContent
}
}
function
findDuplicateStoreDailyPhoneRows
(
values
=
{})
{
const
rows
=
Array
.
isArray
(
values
[
'F2-107'
])
?
values
[
'F2-107'
]
:
[]
const
indexesByPhone
=
new
Map
()
rows
.
forEach
((
row
,
index
)
=>
{
const
phone
=
String
(
row
?.[
'F2-107-2'
]
??
''
).
trim
()
if
(
!
phone
)
return
indexesByPhone
.
set
(
phone
,
[...(
indexesByPhone
.
get
(
phone
)
||
[]),
index
+
1
])
})
return
[...
indexesByPhone
.
values
()]
.
filter
(
indexes
=>
indexes
.
length
>
1
)
.
flat
()
.
sort
((
left
,
right
)
=>
left
-
right
)
}
function
buildStoreDailySaveThrottleKey
({
merchantId
,
reportDate
,
staffUuid
}
=
{})
{
return
`store-daily-save:
${
merchantId
??
''
}:
$
{
reportDate
??
''
}:
$
{
staffUuid
??
''
}
`
}
function isStoreDailySaveThrottled(lastSavedAt, now = Date.now()) {
const previous = Number(lastSavedAt)
return Number.isFinite(previous) && now - previous < STORE_DAILY_SAVE_THROTTLE_MS
}
function resolveDetailRevisionToken(detail = {}) {
for (const field of ['revisionId', 'versionId', 'updateId']) {
const value = detail[field]
if (value !== null && value !== undefined && String(value) !== '') {
return `
revision
:
$
{
value
}
`
}
}
return `
content
:
$
{
fingerprint
(
stableSerialize
(
normalizeJsonContent
(
detail
.
jsonContent
)))}
`
}
function hasStoreDailyRevisionConflict(base, latest) {
return Boolean(base && latest && base !== latest)
}
module.exports = {
findDuplicateStoreDailyPhoneRows,
buildStoreDailySaveThrottleKey,
isStoreDailySaveThrottled,
resolveDetailRevisionToken,
hasStoreDailyRevisionConflict
}
packageDynamicForm/utils/store-daily-submit-confirm.js
View file @
9beda67
/**
*
@file 门店日报「上报」二次确认弹窗文案
* 纯函数:供
storeDailyReport.onSubmitTap 与单测使用
*
门店日报保存和上报流程的确认弹窗配置。
* 纯函数:供
页面和单元测试共同使用。
*/
/**
* 门店日报上报前 wx.showModal 配置(提醒驻店/洽谈明细完成后再上报)
* @returns {{ title: string, content: string, cancelText: string, confirmText: string }}
*/
function
buildStoreDailySubmitConfirmModal
()
{
return
{
title
:
'确定上报
门店日报
?'
,
title
:
'确定上报
数据
?'
,
content
:
'请确认
驻店人员在当前场景下已完成所有个人的驻店日报及洽谈明细
。门店日报上报后,将立即发送相关门店经营统计数据到指定消息群。'
,
'请确认
已记录今日所有非成交客户信息,并确保成交客户已完成录单
。门店日报上报后,将立即发送相关门店经营统计数据到指定消息群。'
,
cancelText
:
'我再想想'
,
confirmText
:
'确定上报'
confirmText
:
'确定'
}
}
function
buildStoreDailyConflictModal
()
{
return
{
title
:
'数据已被他人更新'
,
content
:
'在你编辑期间,其他用户已完成保存操作。若直接保存,将覆盖对方的最新修改。'
,
cancelText
:
'取消'
,
confirmText
:
'直接保存'
}
}
function
buildStoreDailyLeaveModal
()
{
return
{
title
:
'重要提示'
,
content
:
'内容尚未提交,是否退出编辑?'
,
cancelText
:
'继续编辑'
,
confirmText
:
'确定退出'
}
}
module
.
exports
=
{
buildStoreDailySubmitConfirmModal
buildStoreDailySubmitConfirmModal
,
buildStoreDailyConflictModal
,
buildStoreDailyLeaveModal
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment