package com.ruoyi.frequency.works.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.frequency.works.entity.Works;
import com.ruoyi.frequency.works.model.result.WorksCount;
import com.ruoyi.frequency.works.service.WorksService;
import com.ruoyi.post.frequency.post.entity.Post;
import com.ruoyi.post.frequency.post.model.result.PostCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作品Controller
 *
 * @author zj
 * @date 2023-09-22
 */
@RestController
@RequestMapping("/frequency/works")
public class WorksController extends BaseController
{
    @Autowired
    private WorksService worksService;

    /**
     * 查询作品列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:works:list')")
    @PostMapping("/list")
    public TableDataInfo<Works> list(@RequestBody Works works)
    {
        List<Works> list = worksService.selectWorksList(works);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody Works works)
    {
        WorksCount count = worksService.statistics(works);
        return AjaxResult.success(count);
    }

    /**
     * 导出作品列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:works:export')")
    @Log(title = "作品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Works works)
    {
        List<Works> list = worksService.selectWorksList(works);
        ExcelUtil<Works> util = new ExcelUtil<Works>(Works.class);
        return util.exportExcel(list, "作品数据");
    }

    /**
     * 获取作品详细信息
     */
//    @PreAuthorize("@ss.hasPermi('frequency:works:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Works> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(worksService.selectWorksById(id));
    }

    /**
     * 新增作品
     */
//    @PreAuthorize("@ss.hasPermi('frequency:works:add')")
    @Log(title = "作品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Works works)
    {
        return toAjax(worksService.insertWorks(works));
    }

    /**
     * 修改作品
     */
//    @PreAuthorize("@ss.hasPermi('frequency:works:edit')")
    @Log(title = "作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Works works)
    {
        return toAjax(worksService.updateWorks(works));
    }

    /**
     * 删除作品
     */
//    @PreAuthorize("@ss.hasPermi('frequency:works:remove')")
    @Log(title = "作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(worksService.deleteWorksByIds(ids));
    }
}
