package com.ruoyi.web.controller.dz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dz.domain.DzSelectSubject;
import com.ruoyi.dz.service.IDzSelectSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科目组合Controller
 * 
 * @author ruoyi
 * @date 2025-09-27
 */
@RestController
@RequestMapping("/dz/groups")
public class DzSelectSubjectController extends BaseController
{
    @Autowired
    private IDzSelectSubjectService dzSelectSubjectService;

    /**
     * 查询科目组合列表
     */
    @PreAuthorize("@ss.hasPermi('dz:groups:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzSelectSubject dzSelectSubject)
    {
        startPage();
        List<DzSelectSubject> list = dzSelectSubjectService.selectDzSelectSubjectList(dzSelectSubject);
        return getDataTable(list);
    }

    /**
     * 导出科目组合列表
     */
    @PreAuthorize("@ss.hasPermi('dz:groups:export')")
    @Log(title = "科目组合", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzSelectSubject dzSelectSubject)
    {
        List<DzSelectSubject> list = dzSelectSubjectService.selectDzSelectSubjectList(dzSelectSubject);
        ExcelUtil<DzSelectSubject> util = new ExcelUtil<DzSelectSubject>(DzSelectSubject.class);
        util.exportExcel(response, list, "科目组合数据");
    }

    /**
     * 获取科目组合详细信息
     */
    @PreAuthorize("@ss.hasPermi('dz:groups:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") String groupId)
    {
        return success(dzSelectSubjectService.selectDzSelectSubjectByGroupId(groupId));
    }

    /**
     * 新增科目组合
     */
    @PreAuthorize("@ss.hasPermi('dz:groups:add')")
    @Log(title = "科目组合", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzSelectSubject dzSelectSubject)
    {
        return toAjax(dzSelectSubjectService.insertDzSelectSubject(dzSelectSubject));
    }

    /**
     * 修改科目组合
     */
    @PreAuthorize("@ss.hasPermi('dz:groups:edit')")
    @Log(title = "科目组合", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzSelectSubject dzSelectSubject)
    {
        return toAjax(dzSelectSubjectService.updateDzSelectSubject(dzSelectSubject));
    }

    /**
     * 删除科目组合
     */
    @PreAuthorize("@ss.hasPermi('dz:groups:remove')")
    @Log(title = "科目组合", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable String[] groupIds)
    {
        return toAjax(dzSelectSubjectService.deleteDzSelectSubjectByGroupIds(groupIds));
    }
}
