fix(BS-New-1, BS-New-3): 字典 enCode 自动 skip-duplicate + datetime 自动转 Long
BS-New-1: dict dataCreate 新增 --skip-duplicate (默认 ON)
- 预拉已有 items 检测 enCode/fullName 冲突
- 命中冲突的项自动跳过 (避免后端 EXIST001/EXIST002)
- --no-skip-duplicate 保留旧行为 (强制失败)
BS-New-3: test run POST create 前自动转 ISO8601 → Long
- 根因: 后端 VisualdevModelDataServiceImpl.swapDatetime 强制
Long.parseLong(value), ISO8601 字符串抛 NumberFormatException
- 镜像 web datePicker 默认 Date.now()
- 检测 datePicker/timePicker 字段, 字符串值自动 new Date().getTime()
测试场 (testspace) 验证:
- BS-New-1: 单条/批量 重复 enCode 自动 skip ✓
- BS-New-3: 用户传 ISO8601 → Long → 数据库正确落地 ✓
jxcj 2026-06-30 实战教训
This commit is contained in:
1 parent
2499589fee
commit
720c99d062
8 files changed
+372
-8
No files matched your search
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,152 @@
|
||||
# Patch: _codegen-ServiceImpMarco-virtual-field — codegen 虚拟字段 null 守卫
|
||||
|
||||
**状态**: ✅ 已应用 (2026-06-23, 单点修复)
|
||||
**对应文件**: `boot/resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm`
|
||||
**基线文件**: `jnpf/静态资源/jnpf-resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm`
|
||||
|
||||
> ⚠ **特例说明**: 本目录通常只记录 `web/.../src/**` 前端源码改造。本 patch 是 boot 端 Velocity 模板修改, 是 web-patches 体系的特例 (改动被 JNPF 升级覆盖的风险与 web 端等同). 按用户要求归档在此.
|
||||
|
||||
## 改动原因
|
||||
|
||||
dacli `form codegen` 用 Velocity 模板生成后端 Java + 前端 Vue 代码。
|
||||
|
||||
### Bug 现象
|
||||
|
||||
当表单字段被勾选进 `searchList` (搜索条件) 但**不在主表** (即"虚拟字段", 比如关联副表的查询条件), 模板里的 `SearchTypeModel.afterVModel` 和 `Field.fieldAlias` 为 null.
|
||||
|
||||
原模板无脑引用:
|
||||
|
||||
```vm
|
||||
#set($vModelName = "${SearchTypeModel.afterVModel}")
|
||||
...
|
||||
#set($fieldName = "${vModelName.substring(0,1).toUpperCase()}${vModelName.substring(1)}")
|
||||
```
|
||||
|
||||
Velocity 对 `${null}` 的处理是**输出字面字符串** `${SearchTypeModel.afterVModel.substring(0,1).toUpperCase()}` 到生成的 .java 文件里 → javac 编译失败 (非法语法 `get${SearchTypeModel.afterVModel.substring(0,1).toUpperCase()}()`).
|
||||
|
||||
### 修复思路
|
||||
|
||||
虚拟字段没有对应的 Java getter / 字段, 生成代码无意义 → 直接**整个字段跳过**, 不输出 `if(ObjectUtil.isNotEmpty(...))` 块.
|
||||
|
||||
## 实际改动 (2 处空值守卫)
|
||||
|
||||
### 改动 1: `#macro(PaginationQuery ...)` 块 (~第 143 行)
|
||||
|
||||
```diff
|
||||
#foreach($SearchTypeModel in ${searchListSizes})
|
||||
- #set($vModelName = "${SearchTypeModel.afterVModel}")
|
||||
- #set($fieldAliasName = "${SearchTypeModel.afterVModel}")
|
||||
- #set($tableAliasName = "${SearchTypeModel.tableAliasName}")
|
||||
- #if($SearchTypeModel.id.contains("_jnpf_"))
|
||||
- #set($fieldAliasName = "jnpf_${tableAliasName}_jnpf_${vModelName}")
|
||||
- #elseif($SearchTypeModel.id.toLowerCase().startsWith("tablefield"))
|
||||
- #set($fieldAliasName = "${tableAliasName}_${vModelName}")
|
||||
+ ## ⚠ 2026-06-23 bug fix: SearchTypeModel.afterVModel 在虚拟字段 (searchList 但不在主表) 时为 null.
|
||||
+ ## 原代码 #set($vModelName = "${SearchTypeModel.afterVModel}") 会输出字面 "${SearchTypeModel.afterVModel}"
|
||||
+ ## 然后 $vModelName.substring(...) 输出字面, 最终生成 .java 含 get${SearchTypeModel.afterVModel.substring(...)}() 非法语法.
|
||||
+ ## 修复: afterVModel 空时跳过该字段 (虚拟字段无对应 getter, 不生成查询代码).
|
||||
+ #if("$!{SearchTypeModel.afterVModel}" == "")
|
||||
+ #set($_skip = true)
|
||||
+ #else
|
||||
+ #set($_skip = false)
|
||||
+ #set($vModelName = "${SearchTypeModel.afterVModel}")
|
||||
+ #set($fieldAliasName = "${SearchTypeModel.afterVModel}")
|
||||
+ #set($tableAliasName = "${SearchTypeModel.tableAliasName}")
|
||||
+ #if($SearchTypeModel.id.contains("_jnpf_"))
|
||||
+ #set($fieldAliasName = "jnpf_${tableAliasName}_jnpf_${vModelName}")
|
||||
+ #elseif($SearchTypeModel.id.toLowerCase().startsWith("tablefield"))
|
||||
+ #set($fieldAliasName = "${tableAliasName}_${vModelName}")
|
||||
+ #end
|
||||
+ #set($fieldName = "${vModelName.substring(0,1).toUpperCase()}${vModelName.substring(1)}")
|
||||
+ #set($paginationName ="${fieldAliasName.substring(0,1).toUpperCase()}${fieldAliasName.substring(1)}")
|
||||
#end
|
||||
- #set($fieldName = "${vModelName.substring(0,1).toUpperCase()}${vModelName.substring(1)}")
|
||||
- #set($paginationName ="${fieldAliasName.substring(0,1).toUpperCase()}${fieldAliasName.substring(1)}")
|
||||
+ #if(!$_skip)
|
||||
if(ObjectUtil.isNotEmpty(${name}Pagination.get${paginationName}())){
|
||||
...
|
||||
}
|
||||
+
|
||||
+ #end
|
||||
#end
|
||||
```
|
||||
|
||||
### 改动 2: 字段循环块 (~第 585 行)
|
||||
|
||||
```diff
|
||||
#set($vModel = ${Field.vModel})
|
||||
-#set($upName = "${Field.fieldAlias.substring(0,1).toUpperCase()}${Field.fieldAlias.substring(1)}")
|
||||
+## ⚠ 2026-06-23 bug fix: fieldAlias 在虚拟字段 (searchList 但不在主表) 时为空,
|
||||
+## 原代码无条件 substring(0,1).toUpperCase() 会输出字面 ${Field.fieldAlias.substring(0,1).toUpperCase()}
|
||||
+## 导致 .java 文件含非法 Java 语法, javac 失败.
|
||||
+## 修复: fieldAlias 为空时整个字段跳过 (虚拟字段无对应 Java 字段/getter, 生成代码无意义)
|
||||
+#if("$!{Field.fieldAlias}" != "")
|
||||
+ #set($upName = "${Field.fieldAlias.substring(0,1).toUpperCase()}${Field.fieldAlias.substring(1)}")
|
||||
#if($jnpfKey == 'input' && ...)
|
||||
...
|
||||
#end
|
||||
## 正则判断
|
||||
#RegMethod($jnpfKey,"form.get${upName}()",$config)
|
||||
+#end
|
||||
#end
|
||||
```
|
||||
|
||||
## 验收方法
|
||||
|
||||
### 1. 比对基线 vs 项目
|
||||
|
||||
```bash
|
||||
diff -q ./jnpf/静态资源/jnpf-resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm \
|
||||
./boot/resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm
|
||||
# 期望: 输出 "differ" (补丁在)
|
||||
# 期望空输出: 补丁丢了, 需重应用
|
||||
```
|
||||
|
||||
### 2. 端到端 codegen 验证 (含 searchList 虚拟字段)
|
||||
|
||||
```bash
|
||||
# 准备一张表单, 主表只有 [f_name], 但 searchList 里加一个副表字段 [f_dept_name]
|
||||
# 跑 codegen
|
||||
dacli form codegen <formId> --module=<app> --mainClassName=<Entity>
|
||||
# 期望:
|
||||
# - 生成的 ServiceImpl.java 可 javac 编译
|
||||
# - 不含字面 ${SearchTypeModel.afterVModel.substring(...)} 或类似非法语法
|
||||
# - 虚拟字段不出现在 if(ObjectUtil.isNotEmpty(getXxx())) 块里
|
||||
```
|
||||
|
||||
### 3. 跑 baseline 验证 codegen 没回归
|
||||
|
||||
```bash
|
||||
SKIP_PLAYWRIGHT=1 bash .claude/skills/dacli-ts/examples/baseline/all.sh
|
||||
# 期望: 0 错误, codegen 相关 baseline 全 PASS
|
||||
```
|
||||
|
||||
## JNPF 升级后如何重应用
|
||||
|
||||
JNPF 平台 release 后:
|
||||
|
||||
```bash
|
||||
# 1. 对比基线 (升级后的 jnpf-resources) vs 项目 (boot/resources)
|
||||
diff -rq ./jnpf/静态资源/jnpf-resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm \
|
||||
./boot/resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm
|
||||
# 期望: "differ" → 补丁还在
|
||||
|
||||
# 2. 如果基线已修复 (升级后模板自身已加 null 守卫):
|
||||
# - boot 端可删除补丁, 保持和基线一致
|
||||
# - 更新本文档状态为 "✅ 已合并到基线 (vX.Y.Z+)"
|
||||
|
||||
# 3. 如果基线未修复 (仍存在 null 引用):
|
||||
# - 补丁仍需保留
|
||||
# - 检查改动 1/2 的宏结构是否还匹配 (JNPF 升级可能改写 #macro 结构 → 重应用)
|
||||
```
|
||||
|
||||
## 不需要做的事
|
||||
|
||||
- ❌ 不要改 `jnpf/静态资源/jnpf-resources/TemplateCodeVue3/PublicMacro/ServiceImpMarco.vm` (基线只读)
|
||||
- ❌ 不要在 dacli 端 (`dacli/src/commands/codegen/`) 重复实现模板守卫, 应在 Velocity 模板层修
|
||||
- ❌ 不要把这个守卫抽成通用工具函数 (`#macroNullGuard`), 一次 bug 修一处即可, 避免过度抽象
|
||||
|
||||
## 相关链接
|
||||
|
||||
- 镜像架构: `dacli/docs/architecture-philosophy.md` (模板层修复优先, 不在调用层打补丁)
|
||||
- CI 关卡 G: `dacli/src/commands/_gate_webapi.ts` (本 patch 不直接走 CI G, 因改的是后端模板)
|
||||
@@ -0,0 +1,125 @@
|
||||
# Patch: _jnpf-admin-scanBasePackages-ssw — 主入口扫 ssw 包
|
||||
|
||||
**状态**: ✅ 已应用 (2026-04-07)
|
||||
**对应文件**: `boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java`
|
||||
**基线文件**: `jnpf/后端/jnpf-java-boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java`
|
||||
|
||||
> ⚠ **特例说明**: 本目录通常只记录 `web/.../src/**` 前端源码改造。本 patch 是 boot 主入口对 JNPF 基线的最小定制 (单行注解参数), 是 web-patches 体系的特例 (改动被 JNPF 升级覆盖的风险与 web 端等同). 按用户要求归档在此.
|
||||
|
||||
## 改动原因
|
||||
|
||||
JNPF 平台基线 `@SpringBootApplication` 默认只扫 `@SpringBootApplication` 类**所在包及其子包**:
|
||||
|
||||
- `JnpfAdminApplication` 类在 `jnpf` 包下 → 默认只扫 `jnpf.*`
|
||||
- 不扫其他顶层包 (如 `com.xxl.job.admin.dao` 通过 `@MapperScan` 单独处理, MyBatis 范畴)
|
||||
|
||||
项目加入 ssw 业务模块后:
|
||||
- `boot/ssw-common/ssw-common-biz/src/main/java/ssw/common/...` (包 `ssw.common.*`)
|
||||
- `boot/ssw-common/ssw-common-controller/.../ssw/common/...` (包 `ssw.common.controller.*`)
|
||||
|
||||
这些模块的 `@Component` / `@Service` / `@Controller` / `@Configuration` bean 不在 `jnpf.*` 包下, **Spring 启动时不会注册它们** → 启动失败 / 运行期 NPE / `@Autowired` 拿不到 bean.
|
||||
|
||||
加 `"ssw"` scanBasePackages 是**必要且标准**做法.
|
||||
|
||||
## 实际改动 (1 行注解参数)
|
||||
|
||||
```diff
|
||||
@Slf4j
|
||||
-@SpringBootApplication(scanBasePackages = {"jnpf"}, exclude = {DataSourceAutoConfiguration.class})
|
||||
+@SpringBootApplication(scanBasePackages = {"jnpf","ssw"}, exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFileStorage
|
||||
public class JnpfAdminApplication extends SpringBootServletInitializer {
|
||||
```
|
||||
|
||||
**修改时间**: 2026-04-07 (基线 mtime 2026-03-12)
|
||||
**风险**: 极低 — 只扩大 Spring 扫描范围, 不改任何业务逻辑.
|
||||
|
||||
## 包路径核对
|
||||
|
||||
```
|
||||
boot/ssw-common/ssw-common-biz/src/main/java/ssw/common/... ← 包 ssw.common.*
|
||||
boot/ssw-common/ssw-common-controller/.../ssw/common/controller/... ← 包 ssw.common.controller.*
|
||||
boot/ssw-common/ssw-common-entity/.../ssw/common/entity/... ← 包 ssw.common.entity.*
|
||||
```
|
||||
|
||||
`scanBasePackages = "ssw"` 会覆盖 `ssw.*` 所有子包. **匹配正确**.
|
||||
|
||||
## 与 SswMapperConfig 的关系
|
||||
|
||||
CLAUDE.md §3.6 提到 `ssw-common-biz/.../config/SswMapperConfig.java` 提供 `@MapperScan("ssw.**.mapper")` — 那是 MyBatis mapper 扫描范畴.
|
||||
|
||||
本 patch 是 **Spring 组件扫描** (@Component / @Service / @Controller / @Configuration), 两个机制**独立、不冲突**:
|
||||
|
||||
| 机制 | 处理对象 | 配置位置 |
|
||||
|------|---------|---------|
|
||||
| Spring 组件扫描 | @Component / @Service / @Controller / @Configuration | `@SpringBootApplication(scanBasePackages=...)` (本 patch) |
|
||||
| MyBatis mapper 扫描 | @Mapper 标记的 DAO 接口 | `SswMapperConfig.java` (@MapperScan) |
|
||||
|
||||
## 验收方法
|
||||
|
||||
### 1. 比对基线 vs 项目
|
||||
|
||||
```bash
|
||||
diff -u jnpf/后端/jnpf-java-boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java \
|
||||
boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java
|
||||
# 期望: 输出本 patch 那 1 行 diff (补丁在)
|
||||
# 期望空输出: 补丁丢了, 需重应用
|
||||
```
|
||||
|
||||
### 2. 启动验证 (Spring 实际扫到 ssw bean)
|
||||
|
||||
```bash
|
||||
# 启动 jnpf-admin
|
||||
java -jar boot/jnpf-admin/target/jnpf-admin-*.jar --spring.profiles.active=dev
|
||||
|
||||
# 期望:
|
||||
# 1. 启动日志无 "Field X required a bean of type Y that could not be found"
|
||||
# 2. ssw-common 的 @Configuration 类生效 (如 SswMapperConfig 加载)
|
||||
# 3. ssw-common controller 注册成功 (访问 /ssw/xxx 端点不报 404)
|
||||
|
||||
# 反向验证 (临时回滚看会失败):
|
||||
sed -i 's/scanBasePackages = {"jnpf","ssw"}/scanBasePackages = {"jnpf"}/' \
|
||||
boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java
|
||||
# 重启 → 期望: 启动报错或 controller 404, 证明本 patch 必要
|
||||
# 改回来
|
||||
```
|
||||
|
||||
### 3. 跑 baseline 验证
|
||||
|
||||
```bash
|
||||
SKIP_PLAYWRIGHT=1 bash .claude/skills/dacli-ts/examples/baseline/all.sh
|
||||
# 期望: 0 错误, 启动 + 业务接口 baseline 全 PASS
|
||||
```
|
||||
|
||||
## JNPF 升级后如何重应用
|
||||
|
||||
JNPF 平台 release 后:
|
||||
|
||||
```bash
|
||||
# 1. 对比基线 (升级后的 jnpf-java-boot) vs 项目 (boot/jnpf-admin)
|
||||
diff jnpf/后端/jnpf-java-boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java \
|
||||
boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java
|
||||
# 期望: scanBasePackages 仍是 {"jnpf","ssw"} → 补丁还在
|
||||
|
||||
# 2. 如果 JNPF 升级已自带 ssw 扫描 (基线 = 项目):
|
||||
# - 无需操作, 补丁已合并到基线
|
||||
# - 更新本文档状态为 "✅ 已合并到基线 (vX.Y.Z+)"
|
||||
|
||||
# 3. 如果基线未带 ssw 扫描 (升级后被覆盖回 {"jnpf"}):
|
||||
# - 重应用本 patch (1 行改回)
|
||||
# - 跑 baseline 验证
|
||||
# - JNPF 升级后此文件大概率会回到基线 (JNPF 升级默认覆盖标准文件),
|
||||
# 所以这个 patch 几乎每次升级都要重新应用, 标注 ⚠
|
||||
```
|
||||
|
||||
## 不需要做的事
|
||||
|
||||
- ❌ 不要改 `jnpf/后端/jnpf-java-boot/jnpf-admin/src/main/java/jnpf/JnpfAdminApplication.java` (基线只读)
|
||||
- ❌ 不要把 scanBasePackages 改成包列表 (数组), 单字符串 `"ssw"` 已经覆盖所有 ssw.* 子包, 列表化无意义
|
||||
- ❌ 不要在 ssw-common 模块的每个 @SpringBootTest 里单独 @ComponentScan — 主入口扫到就够了, 子模块测试继承主配置
|
||||
|
||||
## 相关链接
|
||||
|
||||
- ssw-common 共享 MapperConfig: CLAUDE.md §3.6 (BS-14 集中化, 解释为什么本 patch 不需要重复 @MapperScan)
|
||||
- 镜像架构: `dacli/docs/architecture-philosophy.md` (定制基线时改最小集, 不动业务逻辑)
|
||||
- CI 关卡 G: `dacli/src/commands/_gate_webapi.ts` (本 patch 不直接走 CI G, 因改的是后端启动配置)
|
||||
Vendored
BIN
Binary file not shown.
@@ -3,6 +3,11 @@
|
||||
*
|
||||
* v0.11+ Phase 2 (2026-06-25): 改用 webapi 镜像 (loadDict.createDictionaryData)
|
||||
* 替代 v0.10 直接 c.postJson('/system/DictionaryData')
|
||||
*
|
||||
* v0.12+ BS-New-1 fix: --skip-duplicate (默认 ON)
|
||||
* - 预拉取 typeId 下已有 items, 检测 enCode + fullName 冲突
|
||||
* - 命中冲突的项自动跳过, 警告日志明确告诉用户
|
||||
* - --no-skip-duplicate 强制创建 (后端会返 EXIST001/EXIST002)
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
@@ -19,19 +24,23 @@ interface Opts {
|
||||
parentId?: string
|
||||
sortCode?: string
|
||||
items?: string
|
||||
/** v0.12+ BS-New-1: 跳过已存在的 enCode/fullName 字典项 (避免 EXIST001/EXIST002) */
|
||||
skipDuplicate?: boolean
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildDictDataCreateCommand(): Command {
|
||||
const cmd = new Command('dataCreate')
|
||||
.alias('data-create')
|
||||
.description('往已存在字典类型追加字典项 (单条/批量)')
|
||||
.description('往已存在字典类型追加字典项 (单条/批量, 默认跳过重复)')
|
||||
.requiredOption('--typeId <id>', '字典类型 id')
|
||||
.option('--enCode <e>', '字典项编码 (单条模式必填)')
|
||||
.option('--fullName <n>', '字典项名 (单条模式必填)')
|
||||
.option('--parentId <p>', '父字典项 id (默认 0)', '0')
|
||||
.option('--sortCode <s>', '排序 (默认 0)', '0')
|
||||
.option('--items <json>', '批量 JSON 数组 [{enCode, fullName, sortCode?}, ...] (与 --enCode/--fullName 互斥)')
|
||||
.option('--skip-duplicate', '跳过已存在 enCode/fullName 的项 (避免 EXIST001/EXIST002 报错, 默认 ON)', true)
|
||||
.option('--no-skip-duplicate', '强制创建, 遇重复返错误 (旧行为)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: Opts) => {
|
||||
if (!opts.typeId) {
|
||||
@@ -70,14 +79,63 @@ export function buildDictDataCreateCommand(): Command {
|
||||
]
|
||||
}
|
||||
|
||||
// === step 0.5 (v0.12+ BS-New-1): 预拉已有 items, 检测重复 ===
|
||||
// 后端约束 (jnpf-system-controller/DictionaryDataController.java:create L55-60):
|
||||
// enCode/fullName 在同一 typeId 内唯一, 命中返 EXIST001(名称)/EXIST002(编码)
|
||||
// 见 jnpf-common-core/MsgCode.java: EXIST001 = "名称不能重复"; EXIST002 = "编码不能重复"
|
||||
const skipDup = opts.skipDuplicate !== false // 默认 ON
|
||||
const existingEncodes = new Set<string>()
|
||||
const existingFullNames = new Set<string>()
|
||||
const skippedItems: Array<{ enCode: string; fullName: string; reason: string }> = []
|
||||
|
||||
if (skipDup && items.length >= 1) {
|
||||
try {
|
||||
const existing = (await loadDict.getDictionaryDataList({ typeId: opts.typeId })) as {
|
||||
list?: Array<{ enCode?: string; fullName?: string }>
|
||||
}
|
||||
const existingList = (existing as { list?: unknown[] })?.list || (Array.isArray(existing) ? (existing as unknown[]) : [])
|
||||
for (const e of existingList as Array<{ enCode?: string; fullName?: string }>) {
|
||||
if (e.enCode) existingEncodes.add(e.enCode)
|
||||
if (e.fullName) existingFullNames.add(e.fullName)
|
||||
}
|
||||
if (existingEncodes.size > 0) {
|
||||
log.info(` ↻ 检测到 ${existingEncodes.size} 个已存在字典项, --skip-duplicate 已开启`)
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn(` ⚠ 预拉已存在字典项失败: ${(e as Error).message}, 继续创建 (不跳过)`)
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤重复
|
||||
const toCreate = skipDup
|
||||
? items.filter(it => {
|
||||
if (existingEncodes.has(it.enCode)) {
|
||||
skippedItems.push({ enCode: it.enCode, fullName: it.fullName, reason: 'enCode 已存在' })
|
||||
return false
|
||||
}
|
||||
if (existingFullNames.has(it.fullName)) {
|
||||
skippedItems.push({ enCode: it.enCode, fullName: it.fullName, reason: 'fullName 已存在' })
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
: items
|
||||
|
||||
if (skippedItems.length > 0) {
|
||||
for (const s of skippedItems) {
|
||||
log.warn(` ⊘ 跳过 ${s.enCode} (${s.fullName}): ${s.reason}`)
|
||||
}
|
||||
}
|
||||
|
||||
// === step 1 (批量调用 loadDict.createDictionaryData (后端API) ===
|
||||
log.info(`loadDict.createDictionaryData typeId=${opts.typeId} count=${items.length}`)
|
||||
const skipInfo = skippedItems.length > 0 ? ` (跳过 ${skippedItems.length})` : ''
|
||||
log.info(`loadDict.createDictionaryData typeId=${opts.typeId} count=${toCreate.length}${skipInfo}`)
|
||||
let ok = 0,
|
||||
fail = 0
|
||||
const ids: string[] = []
|
||||
// B-15 fix: JNPF POST /system/DictionaryData 返 {data:null} 无 id.
|
||||
// POST 全成功后用 list 接口反查 (按 enCode), 与 web 端"创建后列表刷新"对齐.
|
||||
for (const it of items) {
|
||||
for (const it of toCreate) {
|
||||
const body = {
|
||||
dictionaryTypeId: opts.typeId,
|
||||
enCode: it.enCode,
|
||||
@@ -104,12 +162,12 @@ export function buildDictDataCreateCommand(): Command {
|
||||
log.warn(` ✗ ${it.enCode}: ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
}
|
||||
}
|
||||
log.info(`完成: 成功 ${ok}, 失败 ${fail}`)
|
||||
if (opts.json) printJson({ typeId: opts.typeId, success: ok, failed: fail, ids })
|
||||
log.info(`完成: 成功 ${ok}, 跳过 ${skippedItems.length}, 失败 ${fail}`)
|
||||
if (opts.json) printJson({ typeId: opts.typeId, success: ok, skipped: skippedItems.length, failed: fail, ids })
|
||||
})
|
||||
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '往已存在字典类型追加字典项 (单条/批量).',
|
||||
purpose: '往已存在字典类型追加字典项 (单条/批量, 自动跳过重复).',
|
||||
required: { '--typeId': '字典类型 id' },
|
||||
optional: {
|
||||
'--enCode': '单条模式: 字典项编码',
|
||||
@@ -117,10 +175,15 @@ export function buildDictDataCreateCommand(): Command {
|
||||
'--items': '批量模式: JSON 数组 [{enCode, fullName, sortCode?}]',
|
||||
'--parentId': '父字典项 id (默认 0)',
|
||||
'--sortCode': '排序 (默认 0)',
|
||||
'--skip-duplicate / --no-skip-duplicate': 'BS-New-1: 跳过 enCode/fullName 重复 (默认 ON)',
|
||||
},
|
||||
example: 'dacli dict dataCreate --typeId=443409825091648261 --enCode=new --fullName="新项"',
|
||||
source: { api: 'POST /api/system/DictionaryData' },
|
||||
notes: ['v0.11+ 改用 webapi 镜像 (loadDict.createDictionaryData)', '解决盲点 41: 往已有字典类型追加字典项'],
|
||||
notes: [
|
||||
'v0.11+ 改用 webapi 镜像 (loadDict.createDictionaryData)',
|
||||
'解决盲点 41: 往已有字典类型追加字典项',
|
||||
'v0.12+ BS-New-1: --skip-duplicate 默认 ON, 自动跳过 enCode/fullName 重复 (web 端 EXIST001/EXIST002 约束)',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
}
|
||||
@@ -200,6 +200,30 @@ export function buildTestRunCommand(): Command {
|
||||
|
||||
// Step 2: POST create
|
||||
const t1 = Date.now()
|
||||
// v0.12+ BS-New-3 fix (2026-06-30 jxcj): datetime 字段自动转 Long 毫秒戳
|
||||
// 根因: 后端 VisualdevModelDataServiceImpl.swapDatetime 强制 Long.parseLong(value),
|
||||
// 传 ISO8601 字符串 ("2026-06-15 00:00:00") 会抛 NumberFormatException
|
||||
// → "System abnormality" (HTTP 400)
|
||||
// 镜像: web 端 datePicker 默认值 = new Date().getTime() (Long)
|
||||
// 修: POST 前扫描 fields 找 datePicker/timePicker, 字符串值自动转 Long
|
||||
let datetimeConvertedCount = 0
|
||||
for (const f of fields) {
|
||||
const key = f?.__config__?.jnpfKey
|
||||
const vmodel = f?.__vModel__
|
||||
if (vmodel && (key === 'datePicker' || key === 'timePicker')) {
|
||||
const val = sample[vmodel]
|
||||
if (typeof val === 'string' && val.trim() !== '' && !/^-?\d+$/.test(val)) {
|
||||
const ts = new Date(val).getTime()
|
||||
if (!isNaN(ts)) {
|
||||
sample[vmodel] = ts
|
||||
datetimeConvertedCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (datetimeConvertedCount > 0) {
|
||||
log.info(` ↻ datetime 字段自动转 Long: ${datetimeConvertedCount} 项 (BS-New-3)`)
|
||||
}
|
||||
const createBody = { data: JSON.stringify(sample) }
|
||||
const createR = (await c.postJson(`/visualdev/OnlineDev/${opts.formId}`, createBody)) as {
|
||||
code: number
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Reference in new issue
Block a user