package com.ruoyi.web.controller.investigate;

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.system.domain.InvestigateTable;
import com.ruoyi.system.service.IInvestigateTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考察主Controller
 *
 * @author ruoyi
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/investigate/table")
public class InvestigateTableController extends BaseController {
    @Autowired
    private IInvestigateTableService investigateTableService;

    /**
     * 查询考察主列表
     */
    @PreAuthorize("@ss.hasPermi('investigate:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvestigateTable investigateTable) {
        startPage();
        return investigateTableService.selectInvestigateTableListData(investigateTable);
    }

    /**
     * 查询考察主列表不分页
     */
    @PreAuthorize("@ss.hasPermi('investigate:table:listPage')")
    @GetMapping("/listPage")
    public TableDataInfo listPage(InvestigateTable investigateTable) {
        List<InvestigateTable> list = investigateTableService.selectInvestigateTableList(investigateTable);
        return getDataTable(list);
    }

    /**
     * 导出考察主列表
     */
    @PreAuthorize("@ss.hasPermi('investigate:table:export')")
    @Log(title = "考察主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvestigateTable investigateTable) {
        List<InvestigateTable> list = investigateTableService.selectInvestigateTableList(investigateTable);
        ExcelUtil<InvestigateTable> util = new ExcelUtil<InvestigateTable>(InvestigateTable.class);
        util.exportExcel(response, list, "考察主数据");
    }

    /**
     * 获取考察主详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(investigateTableService.selectInvestigateTableById(id));
    }

    /**
     * 新增考察主信息
     */
    @PreAuthorize("@ss.hasPermi('investigate:table:add')")
    @Log(title = "考察主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvestigateTable investigateTable) {
        investigateTable.setCreateBy(getUsername());
        return toAjax(investigateTableService.insertInvestigateTable(investigateTable));
    }

    /**
     * 修改考察主
     */
    @PreAuthorize("@ss.hasPermi('investigate:table:edit')")
    @Log(title = "考察主", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody InvestigateTable investigateTable) {
        return toAjax(investigateTableService.updateInvestigateTable(investigateTable));
    }

    /**
     * 删除考察主
     */
    @PreAuthorize("@ss.hasPermi('investigate:table:remove')")
    @Log(title = "考察主", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(investigateTableService.deleteInvestigateTableByIds(ids));
    }

}
