@Override
    @Transactional(rollbackFor = Exception.class)
    public void updateCodegen(CodegenUpdateReqVO updateReqVO) {
        // 校验是否已经存在
        if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) {
            throw exception(CODEGEN_TABLE_NOT_EXISTS);
        }
        // 校验主表字段存在
        if (Objects.equals(updateReqVO.getTable().getTemplateType(), CodegenTemplateTypeEnum.SUB.getType())) {
            if (codegenTableMapper.selectById(updateReqVO.getTable().getMasterTableId()) == null) {
                throw exception(CODEGEN_MASTER_TABLE_NOT_EXISTS, updateReqVO.getTable().getMasterTableId());
            }
            if (CollUtil.findOne(updateReqVO.getColumns(),  // 关联主表的字段不存在
                    column -> column.getId().equals(updateReqVO.getTable().getSubJoinColumnId())) == null) {
                throw exception(CODEGEN_SUB_COLUMN_NOT_EXISTS, updateReqVO.getTable().getSubJoinColumnId());
            }
        }

        // 更新 table 表定义
        CodegenTableDO updateTableObj = BeanUtils.toBean(updateReqVO.getTable(), CodegenTableDO.class);
        codegenTableMapper.updateById(updateTableObj);
        // 更新 column 字段定义
        List<CodegenColumnDO> updateColumnObjs = BeanUtils.toBean(updateReqVO.getColumns(), CodegenColumnDO.class);
        updateColumnObjs.forEach(updateColumnObj -> codegenColumnMapper.updateById(updateColumnObj));
    }
@Test
    public void testUpdateCodegen_sub_columnNotExists() {
        // mock 数据
        CodegenTableDO subTable = randomPojo(CodegenTableDO.class,
                o -> o.setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
                        .setScene(CodegenSceneEnum.ADMIN.getScene()));
        codegenTableMapper.insert(subTable);
        // mock 数据（master）
        CodegenTableDO masterTable = randomPojo(CodegenTableDO.class,
                o -> o.setTemplateType(CodegenTemplateTypeEnum.MASTER_ERP.getType())
                        .setScene(CodegenSceneEnum.ADMIN.getScene()));
        codegenTableMapper.insert(masterTable);
        // 准备参数
        CodegenUpdateReqVO updateReqVO = randomPojo(CodegenUpdateReqVO.class,
                o -> o.getTable().setId(subTable.getId())
                        .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
                        .setMasterTableId(masterTable.getId()));

        // 调用，并断言
        assertServiceException(() -> codegenService.updateCodegen(updateReqVO),
                CODEGEN_SUB_COLUMN_NOT_EXISTS, updateReqVO.getTable().getSubJoinColumnId());
    }