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.KeyAreas;
import com.ruoyi.system.service.IKeyAreasService;
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/areas")
public class KeyAreasController extends BaseController
{
    private String prefix = "system/areas";

    @Autowired
    private IKeyAreasService keyAreasService;

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

    /**
     * 查询重点区域列表
     */
    @RequiresPermissions("system:areas:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KeyAreas keyAreas)
    {
        startPage();
        List<KeyAreas> list = keyAreasService.selectKeyAreasList(keyAreas);
        return getDataTable(list);
    }

    /**
     * 导出重点区域列表
     */
    @RequiresPermissions("system:areas:export")
    @Log(title = "重点区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KeyAreas keyAreas)
    {
        List<KeyAreas> list = keyAreasService.selectKeyAreasList(keyAreas);
        ExcelUtil<KeyAreas> util = new ExcelUtil<KeyAreas>(KeyAreas.class);
        return util.exportExcel(list, "重点区域数据");
    }

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

    /**
     * 新增保存重点区域
     */
    @RequiresPermissions("system:areas:add")
    @Log(title = "重点区域", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KeyAreas keyAreas)
    {
        return toAjax(keyAreasService.insertKeyAreas(keyAreas));
    }

    /**
     * 修改重点区域
     */
    @RequiresPermissions("system:areas:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KeyAreas keyAreas = keyAreasService.selectKeyAreasById(id);
        mmap.put("keyAreas", keyAreas);
        return prefix + "/edit";
    }

    /**
     * 修改保存重点区域
     */
    @RequiresPermissions("system:areas:edit")
    @Log(title = "重点区域", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KeyAreas keyAreas)
    {
        return toAjax(keyAreasService.updateKeyAreas(keyAreas));
    }

    /**
     * 删除重点区域
     */
    @RequiresPermissions("system:areas:remove")
    @Log(title = "重点区域", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(keyAreasService.deleteKeyAreasByIds(ids));
    }
}
