Compare commits

..
Author SHA1 Message Date
zlwuandCursor 5109d8b3e5 fix(backend): 计划开始时间筛选不再内置工单状态限制
去掉 EXISTS 中对工单/任务/步骤活跃态的硬编码,日期条件与前端勾选的状态等检索项组合生效,修复区间内有步骤日期却查空的问题。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 10:20:59 +08:00
zlwuandCursor 2a0a2ef72a feat(web-admin): 历史归属维护支持批量调整归属
在历史归属维护列表增加多选与工具栏批量「调整归属」,复用现有单条预览/保存接口逐条提交,便于一次将多条业务记录归属到同一项目。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 10:02:24 +08:00
zlwu 3a396d79a2 chore(mobile-h5): 切换本地联调环境与测试 AppID
continuous-integration/drone/tag Build is passing
按用户本地验收要求,将 APP_ENV 切换为 local,使用本机 API 和移动 H5 地址,并将微信 AppID 切换为测试号。
2026-11-10 09:37:04 +08:00
zlwu 9c4944702b fix(db): 补充协议操作日志旧表纠偏脚本
为同名旧表与现行日志模型不兼容的情况提供迁移脚本,并在原建表脚本注明纠偏入口。保留有数据的旧表为备份;本次仅提交现有脚本,未执行数据库迁移。
2026-11-10 09:37:04 +08:00
cykj e06f89dcf6 Merge pull request 'fix(mobile): 修复协议单保存前项目校验异常' (#79) from codex/issue-78-protocol-save into V2.0 2026-11-10 01:24:10 +00:00
7 changed files with 299 additions and 39 deletions

No files matched your search

+1 -7
View File
@@ -94,7 +94,7 @@ def apply_planned_start_time_step_filter(
planned_start_time_end: Optional[str] = None,
mine_user_id: Optional[str] = None,
):
"""按活跃工单/任务下未完成工艺步骤的计划开始时间过滤。"""
"""按工艺步骤计划开始时间过滤;工单/任务/步骤状态由外层检索条件组合控制。"""
start = (planned_start_time_start or "").strip()
end = (planned_start_time_end or "").strip()
if not start and not end:
@@ -104,15 +104,9 @@ def apply_planned_start_time_step_filter(
BizProductionTaskStep.del_flag == 0,
BizProductionTaskStep.tenant_no == tenant_no,
BizProductionTaskStep.planned_start_time.isnot(None),
BizProductionTaskStep.step_status != "ywc",
BizProductionTask.id == BizProductionTaskStep.task_id,
BizProductionTask.del_flag == 0,
BizProductionTask.tenant_no == tenant_no,
BizProductionTask.task_status.in_(("dpz", "jxz")),
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
BizProductionWorkOrder.del_flag == 0,
BizProductionWorkOrder.tenant_no == tenant_no,
BizProductionWorkOrder.work_order_status.in_(("dpz", "jxz")),
work_order_id_column == BizProductionTask.work_order_id,
]
if start:
@@ -0,0 +1,42 @@
"""计划开始时间筛选:不内置工单/任务/步骤状态限制,交给外层组合条件。"""
from sqlalchemy import create_engine
from sqlalchemy.dialects import mysql
from sqlalchemy.orm import sessionmaker
from app.crud.production_work_order import apply_planned_start_time_step_filter
from app.models.models import BizProductionWorkOrder
def _compile_planned_start_sql() -> str:
eng = create_engine("sqlite://")
SessionLocal = sessionmaker(bind=eng)
db = SessionLocal()
try:
q = db.query(BizProductionWorkOrder).filter(BizProductionWorkOrder.del_flag == 0)
filtered = apply_planned_start_time_step_filter(
q,
tenant_no="zkxw",
work_order_id_column=BizProductionWorkOrder.id,
planned_start_time_start="2026-10-01",
planned_start_time_end="2026-12-31",
)
return str(
filtered.statement.compile(
dialect=mysql.dialect(), compile_kwargs={"literal_binds": True}
)
)
finally:
db.close()
def test_planned_start_filter_keeps_date_bounds_without_status_hardcodes():
sql = _compile_planned_start_sql().lower()
assert "planned_start_time" in sql
assert "2026-10-01 00:00:00" in sql
assert "2026-12-31 23:59:59" in sql
# 不再在 EXISTS 内强制待配置/进行中或未完成步骤
assert "work_order_status in (" not in sql
assert "task_status in (" not in sql
assert "step_status !=" not in sql
assert "step_status <>" not in sql
@@ -1,6 +1,10 @@
-- Issue #24:协议单操作过程日志(before / action / after)
-- MySQL 5.7;可重复执行(CREATE IF NOT EXISTS)。上线前须备份并在目标副本验证。
-- DDL 隐式提交;该脚本不作为自动应用启动步骤。
--
-- 注意:若目标库已存在同名「采集协议单操作日志」旧表(含 collection_protocol_id /
-- operation_code 等列),本脚本会因 IF NOT EXISTS 直接跳过,不会纠偏。
-- 生产纠偏请改用:2026-11-09-protocol-operation-log-rebuild.sql
CREATE TABLE IF NOT EXISTS biz_protocol_operation_log (
id VARCHAR(64) NOT NULL,
@@ -0,0 +1,119 @@
-- =============================================================================
-- 协议操作日志:兼容生产旧表同名冲突,重建为 Issue #24 模型
-- MySQL 5.7;可重复执行。上线前须备份,并在目标副本验证。
--
-- 背景:
-- 生产曾有「采集协议单操作日志」同名表(collection_protocol_id / operation_*),
-- 与当前代码(biz_type / before_json / after_json)不兼容。
-- 旧脚本 2026-11-05-protocol-operation-log.sql 使用 CREATE IF NOT EXISTS,
-- 遇到旧表会直接跳过,无法纠偏。本脚本用于生产纠偏与新环境兜底。
--
-- 行为:
-- 1) 已是新模型(有 biz_type)→ 跳过结构变更
-- 2) 旧模型且 0 行 → DROP 后按新模型 CREATE
-- 3) 旧模型且有数据 → RENAME 为 biz_protocol_operation_log_legacy_20261109 再 CREATE
-- 4) 表不存在 → 直接 CREATE
-- =============================================================================
SET @db := DATABASE();
SET @table_exists := (
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = @db AND table_name = 'biz_protocol_operation_log'
);
SET @has_legacy_col := (
SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = @db
AND table_name = 'biz_protocol_operation_log'
AND column_name = 'collection_protocol_id'
);
SET @has_new_col := (
SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = @db
AND table_name = 'biz_protocol_operation_log'
AND column_name = 'biz_type'
);
SET @is_legacy := IF(@table_exists > 0 AND @has_legacy_col > 0 AND @has_new_col = 0, 1, 0);
SET @legacy_rows := 0;
SET @cnt_sql := IF(
@is_legacy = 1,
'SET @legacy_rows = (SELECT COUNT(*) FROM `biz_protocol_operation_log`)',
'SET @legacy_rows = 0'
);
PREPARE pol_stmt FROM @cnt_sql;
EXECUTE pol_stmt;
DEALLOCATE PREPARE pol_stmt;
-- 空旧表:直接删除
SET @drop_sql := IF(
@is_legacy = 1 AND @legacy_rows = 0,
'DROP TABLE `biz_protocol_operation_log`',
'SELECT ''skip drop empty legacy biz_protocol_operation_log'' AS migration_status'
);
PREPARE pol_stmt FROM @drop_sql;
EXECUTE pol_stmt;
DEALLOCATE PREPARE pol_stmt;
-- 有数据的旧表:改名保留,避免丢历史(当前生产为 0 行,通常不会走到这里)
SET @legacy_backup_exists := (
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = @db AND table_name = 'biz_protocol_operation_log_legacy_20261109'
);
SET @rename_sql := IF(
@is_legacy = 1 AND @legacy_rows > 0 AND @legacy_backup_exists = 0,
'RENAME TABLE `biz_protocol_operation_log` TO `biz_protocol_operation_log_legacy_20261109`',
IF(
@is_legacy = 1 AND @legacy_rows > 0 AND @legacy_backup_exists > 0,
'SELECT ''ERROR: legacy backup biz_protocol_operation_log_legacy_20261109 already exists; resolve manually'' AS migration_status',
'SELECT ''skip rename legacy biz_protocol_operation_log'' AS migration_status'
)
);
PREPARE pol_stmt FROM @rename_sql;
EXECUTE pol_stmt;
DEALLOCATE PREPARE pol_stmt;
-- 新模型建表(纠偏后或全新环境)
CREATE TABLE IF NOT EXISTS `biz_protocol_operation_log` (
`id` VARCHAR(64) NOT NULL COMMENT '主键ID',
`biz_type` VARCHAR(32) NOT NULL COMMENT '业务类型 cell_storage/research_donation',
`biz_id` VARCHAR(64) NOT NULL COMMENT '协议单或捐赠单ID',
`protocol_no` VARCHAR(64) NULL COMMENT '协议/捐赠编号快照',
`action` VARCHAR(32) NOT NULL COMMENT '动作 create/update/delete/void/activate/expire/to_research/to_storage/audit',
`client_channel` VARCHAR(16) NOT NULL DEFAULT 'web' COMMENT '来源端 web/mini',
`before_json` MEDIUMTEXT NULL COMMENT '操作前协议信息JSON',
`after_json` MEDIUMTEXT NULL COMMENT '操作后协议信息JSON',
`operator_user_id` VARCHAR(64) NULL COMMENT '操作人用户ID',
`operator_user_name` VARCHAR(64) NULL COMMENT '操作人姓名快照',
`operate_time` DATETIME NOT NULL COMMENT '业务操作时间',
`tenant_no` VARCHAR(64) NOT NULL COMMENT '租户编号',
`order_num` INT NULL COMMENT '排序号',
`remark` VARCHAR(512) NULL COMMENT '备注',
`create_by` VARCHAR(64) NULL COMMENT '创建人id',
`create_dept_id` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '创建人部门ID',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` VARCHAR(64) NULL COMMENT '更新人id',
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`del_flag` SMALLINT NOT NULL DEFAULT 0 COMMENT '删除标记',
PRIMARY KEY (`id`),
KEY `ix_pol_biz` (`tenant_no`, `biz_type`, `biz_id`, `del_flag`),
KEY `ix_pol_time` (`tenant_no`, `operate_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='协议单操作过程日志';
-- 验收:新模型关键列应存在
SELECT
COLUMN_NAME,
COLUMN_TYPE,
IS_NULLABLE,
COLUMN_COMMENT
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'biz_protocol_operation_log'
AND COLUMN_NAME IN (
'biz_type', 'biz_id', 'action', 'before_json', 'after_json',
'client_channel', 'operate_time', 'collection_protocol_id', 'operation_code'
)
ORDER BY ORDINAL_POSITION;
+2 -2
View File
@@ -49,11 +49,11 @@
/* 快应用特有相关 */
"quickapp" : {},
/* 小程序特有相关 */
/* 当前:生产 AppID;切测试时把 appid 改为下方测试值 */
/* 当前:测试 AppID;切生产时把 appid 改为下方生产值 */
/* 生产 AppID:wx2b139581f4c855e4 */
/* 测试 AppID:wxa261ad85f2c99b26 */
"mp-weixin" : {
"appid" : "wx2b139581f4c855e4",
"appid" : "wxa261ad85f2c99b26",
"setting" : {
"urlCheck" : false,
"es6" : true
+1 -1
View File
@@ -6,7 +6,7 @@
*
* 微信公众平台须为对应环境配置 request / 业务域名(HTTPS)
*/
export const APP_ENV = 'prod' // 'local' | 'test' | 'prod'
export const APP_ENV = 'local' // 'local' | 'test' | 'prod'
const ENV_PRESETS = {
local: {
@@ -78,15 +78,41 @@
<el-icon><RefreshRight /></el-icon>重试
</el-button>
</el-alert>
<div v-if="assignment" class="list-toolbar">
<div class="list-toolbar-row">
<div class="list-toolbar-selected">
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
</div>
<el-button
type="primary"
class="btn-main"
:disabled="!selectedRows.length || busy"
@click="openBatch"
>
<el-icon><Edit /></el-icon>调整归属
</el-button>
</div>
</div>
<div class="list-body list-wrap"
><el-table
ref="tableRef"
:key="query.bizType"
:data="rows"
v-loading="loading"
class="list-table"
stripe
row-key="id"
:empty-text="loading ? '正在加载…' : loadError ? '数据加载失败' : '暂无符合条件的单据'"
@selection-change="handleSelectionChange"
>
<el-table-column
v-if="assignment"
type="selection"
min-width="48"
align="center"
header-align="center"
fixed
/>
<el-table-column
type="index"
label="序号"
@@ -151,26 +177,26 @@
>
<el-form class="form-grid-2" label-position="top">
<el-form-item label="原所属项目组">
<el-input :model-value="selected.teamName || '未归属'" disabled />
<el-input :model-value="originalTeamLabel" disabled />
</el-form-item>
<el-form-item label="原所属项目">
<el-input :model-value="selected.projectName || '未归属'" disabled />
<el-input :model-value="originalProjectLabel" disabled />
</el-form-item>
<el-form-item label="新项目组" required>
<ProjectSelect
:key="`team-${selected.id}`"
:key="`team-${dialogSelectKey}`"
team
v-model="targetTeamId"
:biz-type="selected.bizType"
:biz-type="dialogBizType"
@update:model-value="onTargetTeamChange"
/>
</el-form-item>
<el-form-item label="新项目" required>
<ProjectSelect
:key="`project-${selected.id}-${targetTeamId}`"
:key="`project-${dialogSelectKey}-${targetTeamId}`"
v-model="target"
:team-id="targetTeamId"
:biz-type="selected.bizType"
:biz-type="dialogBizType"
:disabled="!targetTeamId"
/>
</el-form-item>
@@ -262,6 +288,7 @@
page: 1,
pageSize: 20
})
const tableRef = ref<{ clearSelection?: () => void } | null>(null)
const rows = ref<ProjectRecord[]>([]),
total = ref(0),
statusCounts = ref<Record<string, number>>({}),
@@ -273,6 +300,8 @@
target = ref(''),
reason = ref(''),
selected = ref<ProjectRecord>({}),
selectedRows = ref<ProjectRecord[]>([]),
editTargets = ref<ProjectRecord[]>([]),
historyVisible = ref(false),
historyRows = ref<ProjectRecord[]>([])
const visibleColumns = computed(() =>
@@ -283,6 +312,39 @@
const keywordHint = computed(() =>
query.bizType === 'presign' ? '请输入单据编号' : assignmentKeywordHints[query.bizType]
)
const dialogBizType = computed(
() =>
(editTargets.value[0]?.bizType ||
selected.value.bizType ||
query.bizType) as AssignmentBizType
)
const dialogSelectKey = computed(() => {
if (editTargets.value.length <= 1) {
return String(editTargets.value[0]?.id || selected.value.id || 'empty')
}
const firstId = editTargets.value[0]?.id || ''
const lastId = editTargets.value[editTargets.value.length - 1]?.id || ''
return `batch-${editTargets.value.length}-${firstId}-${lastId}`
})
const originalTeamLabel = computed(() => {
if (editTargets.value.length <= 1) {
return editTargets.value[0]?.teamName || selected.value.teamName || '未归属'
}
return `共 ${editTargets.value.length} 条`
})
const originalProjectLabel = computed(() => {
if (editTargets.value.length <= 1) {
return editTargets.value[0]?.projectName || selected.value.projectName || '未归属'
}
return `共 ${editTargets.value.length} 条`
})
function clearSelection() {
selectedRows.value = []
tableRef.value?.clearSelection?.()
}
function handleSelectionChange(selection: ProjectRecord[]) {
selectedRows.value = selection
}
let loadVersion = 0
function statusLabel(status: string) {
return query.bizType === 'presign'
@@ -307,6 +369,7 @@
loading.value = true
loadError.value = false
rows.value = []
clearSelection()
try {
const fetchRecords = props.assignment
? fetchAssignmentRecords
@@ -344,6 +407,7 @@
statusCounts.value = {}
visible.value = false
historyVisible.value = false
clearSelection()
search()
}
function switchBusiness(kind: AssignmentBizType) {
@@ -360,16 +424,41 @@
query.page = page
load()
}
function open(row: ProjectRecord) {
selected.value = row
function resetDialogForm(targets: ProjectRecord[]) {
editTargets.value = targets
selected.value = targets[0] || {}
targetTeamId.value = ''
target.value = ''
reason.value = ''
visible.value = true
}
function open(row: ProjectRecord) {
resetDialogForm([row])
}
function openBatch() {
if (!selectedRows.value.length) {
ElMessage.warning('请先选择要调整的记录')
return
}
resetDialogForm([...selectedRows.value])
}
function onTargetTeamChange() {
target.value = ''
}
async function assignOne(row: ProjectRecord, projectId: string, assignReason: string) {
const preview = await previewAssignment({
bizType: row.bizType,
id: row.id,
projectId
})
await saveAssignment({
bizType: row.bizType,
id: row.id,
projectId,
reason: assignReason,
expectedAssignments: assignmentSnapshot(preview.records)
})
}
async function commit() {
if (!targetTeamId.value) {
ElMessage.warning('请选择新项目组')
@@ -383,33 +472,45 @@
ElMessage.warning('请填写调整原因')
return
}
const targets = editTargets.value.length ? [...editTargets.value] : [selected.value]
if (!targets.length || !targets[0]?.id) {
ElMessage.warning('请选择要调整的记录')
return
}
busy.value = true
const commitTarget = target.value
const commitRecord = selected.value
const commitReason = reason.value.trim()
const commitTargets = targets
let successCount = 0
let failCount = 0
try {
const preview = await previewAssignment({
bizType: selected.value.bizType,
id: selected.value.id,
projectId: target.value
})
if (selected.value !== commitRecord || target.value !== commitTarget || !visible.value) {
for (const row of commitTargets) {
if (target.value !== commitTarget || !visible.value) {
return
}
try {
await assignOne(row, commitTarget, commitReason)
successCount += 1
} catch {
failCount += 1
// API layer already surfaces the conflict / validation message.
}
}
if (target.value !== commitTarget || !visible.value) {
return
}
await saveAssignment({
bizType: selected.value.bizType,
id: selected.value.id,
projectId: target.value,
reason: reason.value.trim(),
expectedAssignments: assignmentSnapshot(preview.records)
})
if (selected.value !== commitRecord || target.value !== commitTarget || !visible.value) {
return
if (successCount > 0) {
visible.value = false
clearSelection()
if (failCount === 0) {
ElMessage.success(
commitTargets.length > 1 ? `已调整 ${successCount} 条归属` : '归属已调整'
)
} else {
ElMessage.warning(`成功 ${successCount} 条,失败 ${failCount} 条`)
}
await load()
}
visible.value = false
ElMessage.success('归属已调整')
await load()
} catch {
// API layer already surfaces the conflict / validation message.
} finally {
busy.value = false
}