package com.ruoyi.web.controller.progress;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysMilestone;
import com.ruoyi.system.service.ISysMilestoneService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/progress/milestone")
public class SysMilestoneController extends BaseController
{
    @Autowired
    private ISysMilestoneService sysMilestoneService;

    @PreAuthorize("@ss.hasPermi('progress:milestone:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMilestone sysMilestone)
    {
        startPage();
        List<SysMilestone> list = sysMilestoneService.selectSysMilestoneList(sysMilestone);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('progress:milestone:export')")
    @Log(title = "里程碑事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMilestone sysMilestone)
    {
        List<SysMilestone> list = sysMilestoneService.selectSysMilestoneList(sysMilestone);
        ExcelUtil<SysMilestone> util = new ExcelUtil<SysMilestone>(SysMilestone.class);
        util.exportExcel(response, list, "里程碑事件数据");
    }

    @PreAuthorize("@ss.hasPermi('progress:milestone:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysMilestoneService.selectSysMilestoneById(id));
    }

    @PreAuthorize("@ss.hasPermi('progress:milestone:add')")
    @Log(title = "里程碑事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMilestone sysMilestone)
    {
        return toAjax(sysMilestoneService.insertSysMilestone(sysMilestone));
    }

    @PreAuthorize("@ss.hasPermi('progress:milestone:edit')")
    @Log(title = "里程碑事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMilestone sysMilestone)
    {
        return toAjax(sysMilestoneService.updateSysMilestone(sysMilestone));
    }

    @PreAuthorize("@ss.hasPermi('progress:milestone:remove')")
    @Log(title = "里程碑事件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMilestoneService.deleteSysMilestoneByIds(ids));
    }
}
