package com.ruoyi.hezhi.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.hezhi.domain.TbTrends;
import com.ruoyi.hezhi.service.ITbTrendsService;
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 ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/hezhi/trends")
public class TbTrendsController extends BaseController
{
    @Autowired
    private ITbTrendsService tbTrendsService;

    /**
     * 查询院内动态列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:trends:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTrends tbTrends)
    {
        startPage();
        List<TbTrends> list = tbTrendsService.selectTbTrendsList(tbTrends);
        return getDataTable(list);
    }

    /**
     * 导出院内动态列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:trends:export')")
    @Log(title = "院内动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTrends tbTrends)
    {
        List<TbTrends> list = tbTrendsService.selectTbTrendsList(tbTrends);
        ExcelUtil<TbTrends> util = new ExcelUtil<TbTrends>(TbTrends.class);
        util.exportExcel(response, list, "院内动态数据");
    }

    /**
     * 获取院内动态详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:trends:query')")
    @GetMapping(value = "/{trendsId}")
    public AjaxResult getInfo(@PathVariable("trendsId") Long trendsId)
    {
        return success(tbTrendsService.selectTbTrendsByTrendsId(trendsId));
    }

    /**
     * 新增院内动态
     */
    @PreAuthorize("@ss.hasPermi('hezhi:trends:add')")
    @Log(title = "院内动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTrends tbTrends)
    {
        return toAjax(tbTrendsService.insertTbTrends(tbTrends));
    }

    /**
     * 修改院内动态
     */
    @PreAuthorize("@ss.hasPermi('hezhi:trends:edit')")
    @Log(title = "院内动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTrends tbTrends)
    {
        return toAjax(tbTrendsService.updateTbTrends(tbTrends));
    }

    /**
     * 删除院内动态
     */
    @PreAuthorize("@ss.hasPermi('hezhi:trends:remove')")
    @Log(title = "院内动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trendsIds}")
    public AjaxResult remove(@PathVariable Long[] trendsIds)
    {
        return toAjax(tbTrendsService.deleteTbTrendsByTrendsIds(trendsIds));
    }
}
