Files
gxwebsoft bc5b5bf8ff fix(cms): 修复空更新时生成非法SQL的问题
- 引入BeanUtil判断实体是否有除id和deleted外的非空字段
- 避免MyBatis-Plus在无可更新字段时生成缺SET子句的SQL
- 防止多租户插件jsqlparser因SQL异常而失败
- 空更新场景返回幂等成功结果
- 保持原有代码逻辑,确保业务修改正确执行
2026-08-11 07:42:32 +08:00

1.6 KiB
Raw Permalink Blame History

2026-08-11 工作记录

日志诊断:cms-api (websoft-modules) 报错

来源文件:/Users/gxwebsoft/Downloads/websoft-modules (1).log

主报错(反复出现,需修复)

  • 现象:CmsWebsiteController.update()updateById(cmsWebsite) 生成非法 SQL UPDATE cms_website WHERE website_id=? AND deleted=0SET 子句为空)
  • 抛错链:MyBatis-Plus TenantLineInnerInterceptor 用 jsqlparser 解析该空 SET SQL → ParseException: Encountered unexpected token: "WHERE"MybatisPlusException: Failed to process
  • 根因:application.yml 未设置全局 field-strategyMP 3.4.x 默认 NOT_NULL。当 PUT /cms/website 的 body 只有 websiteIdwebsiteCode 被置 null,其余字段全 null)时,updateById 没有任何非空字段可写 → SET 为空 → SQL 非法。
  • 实体佐证:CmsWebsite@TableLogic deleted 进 WHERE、@TableId websiteId 进 WHERE、updateTime@TableField(fill) 自动填充 → 无字段兜底。
  • 已修复(2026-08-11):在 CmsWebsiteController.update() 调用 updateById 前,用 BeanUtil.beanToMap 判断是否存在非 id/deleted 的非空字段;为空则直接 success 跳过 DB 更新。已新增 import cn.hutool.core.bean.BeanUtil

次要报错(非紧急)

  • 01:44:17 MQTTclient hjm_car_1786362857263 keepAlive=20s 超时,MQTT连接丢失(GPS 回调)。Paho 通常会自动重连,疑为 broker 网络/keepalive 问题。
  • 07:35:20 WARN DruidremoveAbandoned is true, not use in production. 连接池 abandoned 清理开启,Druid 不建议生产环境开启,属配置告警。