package com.ruoyi.frequency.workstype.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.workstype.entity.WorksType;
import com.ruoyi.frequency.workstype.service.WorksTypeService;
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/workstype")
public class WorksTypeController extends BaseController
{
    @Autowired
    private WorksTypeService worksTypeService;

    /**
     * 查询作品类型列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:workstype:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody WorksType worksType)
    {
        startPage();
        List<WorksType> list = worksTypeService.selectWorksTypeList(worksType);
        return getDataTable(list);
    }

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

    /**
     * 获取作品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(worksTypeService.selectWorksTypeById(id));
    }

    /**
     * 新增作品类型
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstype:add')")
    @Log(title = "作品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorksType worksType)
    {
        return toAjax(worksTypeService.insertWorksType(worksType));
    }

    /**
     * 修改作品类型
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstype:edit')")
    @Log(title = "作品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorksType worksType)
    {
        return toAjax(worksTypeService.updateWorksType(worksType));
    }

    /**
     * 删除作品类型
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstype:remove')")
    @Log(title = "作品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable Long[] ids,@PathVariable Integer delFlag)
    {
        return toAjax(worksTypeService.deleteWorksTypeByIds(ids,delFlag));
    }

    /**
     * 查询二级分类
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstype:twoWorksTypeList')")
    @PostMapping("/twoLevelList")
    public AjaxResult twoLevelList()
    {
        return worksTypeService.twoLevelList();
    }
}
