package com.ruoyi.web.controller.back;

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.voluntary.domain.SelectedGroup;
import com.ruoyi.voluntary.service.ISelectedGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科目组合Controller
 * 
 * @author voluntary
 * @date 2023-03-17
 */
@RestController
@RequestMapping("/voluntary/selectedGroup")
public class BackSelectedGroupController extends BaseController
{
    @Autowired
    private ISelectedGroupService selectedGroupService;

    /**
     * 查询科目组合列表
     */
    @PreAuthorize("@ss.hasPermi('voluntary:selectedGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(SelectedGroup selectedGroup)
    {
        startPage();
        List<SelectedGroup> list = selectedGroupService.selectSelectedGroupList(selectedGroup);
        return getDataTable(list);
    }

    @GetMapping("/all")
    public TableDataInfo all() {
        List<SelectedGroup> list = selectedGroupService.selectSelectedGroupList(new SelectedGroup());
        return getDataTable(list);
    }

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

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

    /**
     * 新增科目组合
     */
    @PreAuthorize("@ss.hasPermi('voluntary:selectedGroup:add')")
    @Log(title = "科目组合", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SelectedGroup selectedGroup)
    {
        return toAjax(selectedGroupService.insertSelectedGroup(selectedGroup));
    }

    /**
     * 修改科目组合
     */
    @PreAuthorize("@ss.hasPermi('voluntary:selectedGroup:edit')")
    @Log(title = "科目组合", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SelectedGroup selectedGroup)
    {
        return toAjax(selectedGroupService.updateSelectedGroup(selectedGroup));
    }

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