package com.ruoyi.web.controller.risk;

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.validation.annotation.Validated;
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.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.system.domain.RiskProject;
import com.ruoyi.system.service.IRiskProjectService;

/**
 * 项目管理控制器
 */
@Controller
@RequestMapping("/risk/project")
public class RiskProjectController extends BaseController
{
    private String prefix = "risk/project";

    @Autowired
    private IRiskProjectService riskProjectService;

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

    @RequiresPermissions("risk:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskProject riskProject)
    {
        startPage();
        List<RiskProject> list = riskProjectService.selectRiskProjectList(riskProject);
        return getDataTable(list);
    }

    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("risk:project:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskProject riskProject)
    {
        List<RiskProject> list = riskProjectService.selectRiskProjectList(riskProject);
        ExcelUtil<RiskProject> util = new ExcelUtil<RiskProject>(RiskProject.class);
        return util.exportExcel(list, "项目台账数据");
    }

    @RequiresPermissions("risk:project:list")
    @GetMapping("/{projectId}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return AjaxResult.success().put("data", riskProjectService.selectRiskProjectById(projectId));
    }

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

    @RequiresPermissions("risk:project:add")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated RiskProject riskProject)
    {
        riskProject.setCreateBy(getLoginName());
        return toAjax(riskProjectService.insertRiskProject(riskProject));
    }

    @RequiresPermissions("risk:project:edit")
    @GetMapping("/edit/{projectId}")
    public String edit(@PathVariable("projectId") Long projectId, ModelMap mmap)
    {
        mmap.put("riskProject", riskProjectService.selectRiskProjectById(projectId));
        return prefix + "/edit";
    }

    @RequiresPermissions("risk:project:edit")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated RiskProject riskProject)
    {
        riskProject.setUpdateBy(getLoginName());
        return toAjax(riskProjectService.updateRiskProject(riskProject));
    }

    @RequiresPermissions("risk:project:remove")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskProjectService.deleteRiskProjectByIds(ids));
    }
}
