package com.ruoyi.frequency.workstep.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.workstep.entity.WorkStep;
import com.ruoyi.frequency.workstep.service.WorkStepService;
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 liwenlong
 * @date 2023-10-12
 */
@RestController
@RequestMapping("/frequency/workstep")
public class WorkStepController extends BaseController
{
    @Autowired
    private WorkStepService workStepService;

    /**
     * 查询作品踩列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstep:list')")
    @GetMapping("/list")
    public TableDataInfo<WorkStep> list(WorkStep workStep)
    {
        startPage();
        List<WorkStep> list = workStepService.selectWorkStepList(workStep);
        return getDataTable(list);
    }

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

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

    /**
     * 新增作品踩
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstep:add')")
    @Log(title = "作品踩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkStep workStep)
    {
        return toAjax(workStepService.insertWorkStep(workStep));
    }

    /**
     * 修改作品踩
     */
    @PreAuthorize("@ss.hasPermi('frequency:workstep:edit')")
    @Log(title = "作品踩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkStep workStep)
    {
        return toAjax(workStepService.updateWorkStep(workStep));
    }

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