package com.ruoyi.web.controller.branch;

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.branch.domain.TBranchDemocratic;
import com.ruoyi.branch.service.ITBranchDemocraticService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 民主生活会Controller
 * 
 * @author ruoyi
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/branch/democratic")
public class TBranchDemocraticController extends BaseController
{
    @Autowired
    private ITBranchDemocraticService tBranchDemocraticService;

    /**
     * 查询民主生活会列表
     */
    @PreAuthorize("@ss.hasPermi('branch:democratic:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBranchDemocratic tBranchDemocratic)
    {
        startPage();
        List<TBranchDemocratic> list = tBranchDemocraticService.selectTBranchDemocraticList(tBranchDemocratic);
        return getDataTable(list);
    }

    /**
     * 导出民主生活会列表
     */
    @PreAuthorize("@ss.hasPermi('branch:democratic:export')")
    @Log(title = "民主生活会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBranchDemocratic tBranchDemocratic)
    {
        List<TBranchDemocratic> list = tBranchDemocraticService.selectTBranchDemocraticList(tBranchDemocratic);
        ExcelUtil<TBranchDemocratic> util = new ExcelUtil<TBranchDemocratic>(TBranchDemocratic.class);
        util.exportExcel(response, list, "民主生活会数据");
    }

    /**
     * 获取民主生活会详细信息
     */
    @PreAuthorize("@ss.hasPermi('branch:democratic:query')")
    @GetMapping(value = "/{democraticId}")
    public AjaxResult getInfo(@PathVariable("democraticId") Long democraticId)
    {
        return success(tBranchDemocraticService.selectTBranchDemocraticByDemocraticId(democraticId));
    }

    /**
     * 新增民主生活会
     */
    @PreAuthorize("@ss.hasPermi('branch:democratic:add')")
    @Log(title = "民主生活会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBranchDemocratic tBranchDemocratic)
    {
        return toAjax(tBranchDemocraticService.insertTBranchDemocratic(tBranchDemocratic));
    }

    /**
     * 修改民主生活会
     */
    @PreAuthorize("@ss.hasPermi('branch:democratic:edit')")
    @Log(title = "民主生活会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBranchDemocratic tBranchDemocratic)
    {
        return toAjax(tBranchDemocraticService.updateTBranchDemocratic(tBranchDemocratic));
    }

    /**
     * 删除民主生活会
     */
    @PreAuthorize("@ss.hasPermi('branch:democratic:remove')")
    @Log(title = "民主生活会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{democraticIds}")
    public AjaxResult remove(@PathVariable Long[] democraticIds)
    {
        return toAjax(tBranchDemocraticService.deleteTBranchDemocraticByDemocraticIds(democraticIds));
    }
}
