feat(education): add subject and content-entry reference lists for UI selects

This commit is contained in:
2026-08-01 15:00:32 +08:00
parent 35376df79b
commit ddd95ec512

View File

@@ -0,0 +1,60 @@
package cn.iocoder.yudao.module.education.controller.admin.reference;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.education.dal.dataobject.catalog.ContentEntryDO;
import cn.iocoder.yudao.module.education.dal.dataobject.catalog.SubjectDO;
import cn.iocoder.yudao.module.education.dal.mysql.catalog.ContentEntryMapper;
import cn.iocoder.yudao.module.education.dal.mysql.catalog.SubjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* 管理后台 - 教育引用数据(供前端下拉选择使用)
*/
@Tag(name = "管理后台 - 教育引用数据")
@RestController
@RequestMapping("/education")
@Validated
@ConditionalOnProperty(prefix = "yudao.education", name = "enabled", havingValue = "true")
public class EducationReferenceController {
private final SubjectMapper subjectMapper;
private final ContentEntryMapper contentEntryMapper;
public EducationReferenceController(SubjectMapper subjectMapper, ContentEntryMapper contentEntryMapper) {
this.subjectMapper = subjectMapper;
this.contentEntryMapper = contentEntryMapper;
}
public record SimpleRespVO(Long id, String name) {
}
@GetMapping("/subjects/simple-list")
@Operation(summary = "学科下拉列表")
@PreAuthorize("@ss.hasPermission('education:category:query')")
public CommonResult<List<SimpleRespVO>> getSubjectSimpleList() {
Long tenantId = TenantContextHolder.getRequiredTenantId();
return success(subjectMapper.selectActiveList(tenantId, null, null, null, null, null)
.stream().map(subject -> new SimpleRespVO(subject.getId(), subject.getName())).toList());
}
@GetMapping("/content-entries/simple-list")
@Operation(summary = "内容入口下拉列表")
@PreAuthorize("@ss.hasPermission('education:content-node:query')")
public CommonResult<List<SimpleRespVO>> getContentEntrySimpleList() {
Long tenantId = TenantContextHolder.getRequiredTenantId();
return success(contentEntryMapper.selectActiveList(tenantId, null, null, false)
.stream().map(entry -> new SimpleRespVO(entry.getId(), entry.getName())).toList());
}
}