Skip to content

refactor: layered model (dto/vo/bo/po), MyBatis-Plus migration and unified audit fields - #156

Merged
mengnankkkk merged 9 commits into
mainfrom
refactor/clean-code
Sep 24, 2026
Merged

mengnankkkk merged 9 commits into
mainfrom
refactor/clean-code

Conversation

@VLSMB

@VLSMB VLSMB commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

related #155 #144 #38

  • 建立 io.github.malonetalk.model.{dto,vo,bo,po} 分层模型,逐步替代旧的 dto/entity 包;旧包标记废弃,确认无引用后再删除。
  • 统一响应结构:BaseVo + ResultVo,Controller 直接返回 VO,由 BaseVoResponseAdvice 自动包装,异常也返回同一格式。
  • 持久层迁移到 MyBatis-Plus:以 SysUser 链为试点,实体用 SysUserPo、Service 用 BO、Controller 入参 Dto / 出参 Vo,转换交给 MapStruct。
  • 统一审计与逻辑删除:BasePo 上的审计字段由 MetaObjectHandler 自动填充,项目级 AuditableMapper 补齐了 wrapper-only 的 update/delete 审计。
  • 前端同步适配用户列表分页与布尔返回结构;SQL 增加审计字段及增量迁移脚本。

…elds

- relocate ErrorCode from common to exception package and update all imports
- add model package scaffold (po/vo): BasePo carrying the five audit fields,
  SysUserPo extending it, BaseVo and ResultVo; deprecate entity.SysUser
- implement JsonUtil on Jackson ObjectMapper with typed (de)serialization
- add creator_id/updater_id/is_deleted to sys_user and replace unique key
  uk_idp with non-unique index idx_idp so soft-deleted users can be recreated
- add idempotent sys_user audit-column migrations to migration_compatibility.sql
- turn BaseVo into a marker interface; make ResultVo Serializable with
  success()/success(data)/error() factories
- add BaseVoResponseAdvice (ResponseBodyAdvice) to wrap controller
  responses whose declared return type implements BaseVo
- migrate global exception handling to ResultVo with null data, except
  field validation which keeps the legacy Result payload during the
  gray migration
- mark common.Result as deprecated
- delete common.UserContext (static ThreadLocal) and replace it with a
  Spring-managed UserContextHolder implementing ThreadLocalHolder<>
- add model.bo.UserContextBo as the user-context projection; make
  SysUserService.selectAuthProjection return it
- inject UserContextHolder into AuthInterceptor, AgentController,
  AuthController and TableExportController instead of static accessors
- add model.converter.UserConverter MapStruct placeholder
- mark legacy dto/entity packages deprecated via package-info; drop the
  class-level @deprecated on entity.SysUser
- note holder/converter as auxiliary model packages
- AGENTS.md: prefer official Spring Boot starters; route new data
  entities to io.github.malonetalk.model
- replace mybatis-spring-boot-starter with mybatis-plus-spring-boot4-starter
  3.5.17; swap the pagehelper starter for pagehelper core and register
  PageInterceptor manually
- enable MP pagination via PaginationInnerInterceptor(MYSQL); it coexists
  with PageHelper (IPage-param vs ThreadLocal triggers)
- route jsqlparser through mybatis-plus-jsqlparser (5.2, pinned via
  dependencyManagement); adapt SqlExecutor to the 5.2 WithItem API
- annotate BasePo audit fields with @TableField(fill=...) and @TableLogic;
  add BasePoConstants for the field names
- add AuditMetaObjectHandler to fill creator/updater ids and timestamps
  (null-only, tolerant of missing user context)
- make SysUserPo an MP entity (@TableName, @TableId(AUTO), is_super_admin)
- rename mybatis.* config to mybatis-plus.* and widen type-aliases-package
- add model.bo.SysUserBo and a mapper package note; apply spotless license
  headers/formatting; ignore local agents/ notes
- add AuditableMapper<T extends BasePo> as the project base mapper; SysUserMapper
  extends it and exposes CRUD through BaseMapper, keeping only the two shared
  default helpers (selectLocalByUsername, updatePassword)
- move user requests to model.dto (*Dto) and responses to model.vo (*Vo);
  controllers now take Dto and return BaseVo, wrapped by BaseVoResponseAdvice
- service works on SysUserBo; UserConverter maps PO<->BO, BO->VO and
  UserContextBo->UserInfoVo; BatchQueryConverter maps MP IPage to BatchQueryVo
- move initial-admin bootstrap from AdminBootstrapRunner into
  SysUserService.bootstrapInitialAdmin; AuthController no longer uses the mapper
- route writes through entity-based insert/updateById so AuditMetaObjectHandler
  fills creator/updater/timestamps (updatePassword and updateStatus included)
- replace listAll with a paged query (BaseBatchQueryDto -> BatchQueryVo<UserVo>)
- delete entity.SysUser and mapper/SysUserMapper.xml; deprecate the legacy
  convertor package in favour of model.converter
- listUsers now takes page/pageSize/sortOrder and returns PageResponse
- UserManage adds el-pagination and reads items/total from the paged result
- add BooleanVo to api types; resetPassword/updateStatus/changePassword
  now typed against BooleanVo
- update(Wrapper) delegates to update(newEntityInstance(), wrapper) so the
  MetaObjectHandler fills the audit fields
- delete(Wrapper) selects the matching primary keys first and delegates to
  deleteByIds, which MyBatis-Plus audits natively; deleteByMap inherits this
  path
- resolve T via ReflectionKit and instantiate through TableInfo.newInstance()
@github-actions

Copy link
Copy Markdown

Thank you for your contribution! We will review your request as soon as possible. Please review the code yourself using ponytail https://github.com/DietrichGebert/ponytail.

@VLSMB

VLSMB commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@mengnankkkk ptal

@mengnankkkk
mengnankkkk merged commit 9cc5960 into main Sep 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants