hejianhao
2026-09-01 4b4d225c0f8456b8918dc79eec2e093485746d0f
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/live/service/ProjectIntroductionPasswordService.java
@@ -48,7 +48,7 @@
    /**
     * 保存项目介绍密码配置
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public void savePasswordConfig(ProjectIntroductionPasswordRequest req) {
        // 验证密码格式
        if (req.getPasswordEnabled() == 1) {
@@ -78,15 +78,12 @@
            }
            passwordMapper.insert(config);
        } else {
            // 更新
            config.setPasswordEnabled(req.getPasswordEnabled());
            // 更新 - 使用自定义SQL支持设置为null
            String encodedPassword = null;
            if (req.getPasswordEnabled() == 1 && StrUtil.isNotBlank(req.getPassword())) {
                config.setPassword(passwordEncoder.encode(req.getPassword()));
            } else {
                // 不启用密码时,清空密码
                config.setPassword(null);
                encodedPassword = passwordEncoder.encode(req.getPassword());
            }
            passwordMapper.updateById(config);
            passwordMapper.updatePasswordConfig(config.getId(), req.getPasswordEnabled(), encodedPassword);
        }
    }
@@ -111,4 +108,17 @@
                && !config.getPassword().isEmpty()
                && passwordEncoder.matches(inputPassword, config.getPassword());
    }
    /**
     * 检查项目介绍是否启用密码访问
     */
    public boolean isPasswordEnabled() {
        ProjectIntroductionPassword config = passwordMapper.selectOne(
                new LambdaQueryWrapper<ProjectIntroductionPassword>()
                        .eq(ProjectIntroductionPassword::getPasswordEnabled, 1)
                        .orderByAsc(ProjectIntroductionPassword::getId)
                        .last("limit 1")
        );
        return config != null;
    }
}