package com.ruoyi.szxc.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.szxc.domain.SzxcDiscussCentre;
import com.ruoyi.szxc.service.ISzxcDiscussCentreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 议事中心Controller
 * 
 * @author hs
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/szxc/yscentre")
public class SzxcDiscussCentreController extends BaseController
{
    @Autowired
    private ISzxcDiscussCentreService szxcDiscussCentreService;

    /**
     * 查询议事中心列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:yscentre:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcDiscussCentre szxcDiscussCentre)
    {
        startPage();
        List<SzxcDiscussCentre> list = szxcDiscussCentreService.selectSzxcDiscussCentreList(szxcDiscussCentre);
        return getDataTable(list);
    }

    /**
     * 导出议事中心列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:yscentre:export')")
    @Log(title = "议事中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcDiscussCentre szxcDiscussCentre)
    {
        List<SzxcDiscussCentre> list = szxcDiscussCentreService.selectSzxcDiscussCentreList(szxcDiscussCentre);
        ExcelUtil<SzxcDiscussCentre> util = new ExcelUtil<SzxcDiscussCentre>(SzxcDiscussCentre.class);
        util.exportExcel(response, list, "议事中心数据");
    }

    /**
     * 获取议事中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:yscentre:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcDiscussCentreService.selectSzxcDiscussCentreById(id));
    }

    /**
     * 新增议事中心
     */
    @PreAuthorize("@ss.hasPermi('szxc:yscentre:add')")
    @Log(title = "议事中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcDiscussCentre szxcDiscussCentre)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcDiscussCentre.getDeptId()==null){
            szxcDiscussCentre.setDeptId(getDeptId());
        }
        szxcDiscussCentre.setUserId(getUserId());
        return toAjax(szxcDiscussCentreService.insertSzxcDiscussCentre(szxcDiscussCentre));
    }

    /**
     * 修改议事中心
     */
    @PreAuthorize("@ss.hasPermi('szxc:yscentre:edit')")
    @Log(title = "议事中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcDiscussCentre szxcDiscussCentre)
    {
        return toAjax(szxcDiscussCentreService.updateSzxcDiscussCentre(szxcDiscussCentre));
    }

    /**
     * 删除议事中心
     */
    @PreAuthorize("@ss.hasPermi('szxc:yscentre:remove')")
    @Log(title = "议事中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcDiscussCentreService.deleteSzxcDiscussCentreByIds(ids));
    }
}
