package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.KeyProject;
import com.ruoyi.system.service.IKeyProjectService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 重点工程Controller
 *
 * @author ruoyi
 * @date 2023-07-24
 */
@Controller
@RequestMapping("/system/project")
public class KeyProjectController extends BaseController
{
    private String prefix = "system/project";

    @Autowired
    private IKeyProjectService keyProjectService;

    @RequiresPermissions("system:project:view")
    @GetMapping()
    public String project()
    {
        return prefix + "/project";
    }

    /**
     * 查询重点工程列表
     */
    @RequiresPermissions("system:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KeyProject keyProject)
    {
        startPage();
        List<KeyProject> list = keyProjectService.selectKeyProjectList(keyProject);
        return getDataTable(list);
    }

    /**
     * 导出重点工程列表
     */
    @RequiresPermissions("system:project:export")
    @Log(title = "重点工程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KeyProject keyProject)
    {
        List<KeyProject> list = keyProjectService.selectKeyProjectList(keyProject);
        ExcelUtil<KeyProject> util = new ExcelUtil<KeyProject>(KeyProject.class);
        return util.exportExcel(list, "重点工程数据");
    }

    /**
     * 新增重点工程
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存重点工程
     */
    @RequiresPermissions("system:project:add")
    @Log(title = "重点工程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KeyProject keyProject)
    {
        return toAjax(keyProjectService.insertKeyProject(keyProject));
    }

    /**
     * 修改重点工程
     */
    @RequiresPermissions("system:project:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KeyProject keyProject = keyProjectService.selectKeyProjectById(id);
        mmap.put("keyProject", keyProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存重点工程
     */
    @RequiresPermissions("system:project:edit")
    @Log(title = "重点工程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KeyProject keyProject)
    {
        return toAjax(keyProjectService.updateKeyProject(keyProject));
    }

    /**
     * 删除重点工程
     */
    @RequiresPermissions("system:project:remove")
    @Log(title = "重点工程", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(keyProjectService.deleteKeyProjectByIds(ids));
    }
}
