refactor(option): 优化货物类型相关字段结构与样式调整

- 删除重复的“上级货物类型”相关字段配置,移至更合理位置
- 为部分字段增加隐藏和只读属性,避免误操作
- 注释移除样式中max-width限制,调整宽度显示
- 保持字段校验规则一致性,确保表单验证准确
- 代码格式与结构整理,提升可读性和维护性
This commit is contained in:
2026-07-31 15:39:31 +08:00
parent 81b2a3e99b
commit 449719dfe1
3 changed files with 49 additions and 33 deletions

View File

@@ -0,0 +1,15 @@
# 2026-07-31 工作记录
## 货物类型(/base/cargo-type批量导入「全或无」改造
- 需求:批量导入时只要任一行报错,整批都不入库,并返回失败明细 Excel。用户在「事务 vs 校验」之间选了"全或无 + 推荐方案"。
- 结论(已落地):**全量预校验 + 单事务兜底**,而非纯事务或纯校验二选一。
- 后端仓库:`/Users/gxwebsoft/JAVA/tms-erp-api-ws`BladeX本仓库 tms-erp-web-ws 是纯前端,无 Java
- 改动文件:`blade-service/blade-system/.../service/impl/CargoTypeServiceImpl.java`(仅此一文件,未动 Controller/前端)。
- 实现要点:
- `importCargoType` 拆为两阶段:阶段一 `validateImportAll`(只读,不写库)→ 任一失败直接返回失败明细、整批不入库;阶段二 `saveImportAll` 全部通过后才在 `@Transactional` 内统一写库(兜底防半截入库)。
- 补上原缺失的校验:文件内编码全局去重、一级名称去重、二级(同上级)名称去重;二级父级解析同时支持 DB 与"文件内一级映射"(解决"单文件一级在前"场景,二级引用同文件的一级)。
- 原代码其实已是 `@Transactional + setRollbackOnly`,但"边校验边写库"且缺文件内去重/父子引用校验;本次重构成更干净的预校验优先。
- 前端无需改动:`src/views/base/cargo-type.vue` + `utils/import-excel.js` 已支持失败明细 Excel 下载与 `decorateCargoTypeFailDetail` 装饰。
- 验证:本环境无 maven无法编译已做静态核对imports/方法/字段/括号完整,无 TransactionAspectSupport 残留)。需在本地 `mvn -pl blade-service/blade-system compile` 确认。
- 遗留小问题(非本次引入,可选优化):后端二级编码前缀报错文案为"货物类型编码前2位必须与上级货物类型编码一致",而前端 `CARGO_TYPE_FAIL_RULES` 匹配的是"二级编码前2位必须与上级货物类型编码一致",二者不完全一致,导致该错误前端不会追加规则说明(仍会显示原因)。可后续对齐文案。

View File

@@ -60,43 +60,12 @@ export const getCargoTypeOption = ctx => ({
searchSpan: 6,
value: 2,
span: 24,
hide: true,
minWidth: 120,
editDisabled: true,
rules: [{ required: true, message: '请选择货物类型级别', trigger: 'change' }],
change: ({ value }) => ctx.handleTypeLevelChange(value),
},
{
label: '上级货物类型',
prop: 'parentId',
formslot: true,
hide: true,
display: false,
span: 12,
rules: [{ required: true, message: '请选择上级货物类型', trigger: 'change' }],
},
{
label: '上级货物类型',
prop: 'parentCargoName',
slot: true,
addDisplay: false,
editDisplay: false,
display: false,
showOverflowTooltip: true,
minWidth: 160,
},
{
label: '上级货物编码',
prop: 'parentCargoCode',
slot: true,
readonly: true,
editDisabled: true,
addDisplay: false,
editDisplay: false,
display: false,
span: 12,
minWidth: 160,
rules: [{ required: true, message: '请选择上级货物类型', trigger: 'change' }],
},
{
label: '货物类型',
prop: 'cargoName',
@@ -139,6 +108,38 @@ export const getCargoTypeOption = ctx => ({
],
change: ({ value }) => ctx.handleCargoCodeChange(value),
},
{
label: '上级货物类型',
prop: 'parentId',
formslot: true,
hide: true,
display: false,
span: 12,
rules: [{ required: true, message: '请选择上级货物类型', trigger: 'change' }],
},
{
label: '上级货物类型',
prop: 'parentCargoName',
slot: true,
addDisplay: false,
editDisplay: false,
display: false,
showOverflowTooltip: true,
minWidth: 160,
},
{
label: '上级货物编码',
prop: 'parentCargoCode',
slot: true,
readonly: true,
editDisabled: true,
addDisplay: false,
editDisplay: false,
display: false,
span: 12,
minWidth: 160,
rules: [{ required: true, message: '请选择上级货物类型', trigger: 'change' }],
},
{
label: '创建人',
prop: 'createUserName',

View File

@@ -153,7 +153,7 @@
display: flex;
flex: 0 0 100%;
justify-content: flex-end;
max-width: 100%;
//max-width: 100%;
width: 100%;
}