package com.ruoyi.web.controller.business;

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.business.domain.TbArea;
import com.ruoyi.business.service.ITbAreaService;
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 xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/area")
public class TbAreaController extends BaseController
{
    private String prefix = "business/area";

    @Autowired
    private ITbAreaService tbAreaService;

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

    /**
     * 查询地区
列表
     */
    @RequiresPermissions("business:area:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbArea tbArea)
    {
        startPage();
        List<TbArea> list = tbAreaService.selectTbAreaList(tbArea);
        return getDataTable(list);
    }

    /**
     * 导出地区
列表
     */
    @RequiresPermissions("business:area:export")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbArea tbArea)
    {
        List<TbArea> list = tbAreaService.selectTbAreaList(tbArea);
        ExcelUtil<TbArea> util = new ExcelUtil<TbArea>(TbArea.class);
        return util.exportExcel(list, "地区数据");
    }

    /**
     * 新增地区

     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存地区

     */
    @RequiresPermissions("business:area:add")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbArea tbArea)
    {
        return toAjax(tbAreaService.insertTbArea(tbArea));
    }

    /**
     * 修改地区

     */
    @RequiresPermissions("business:area:edit")
    @GetMapping("/edit/{areaId}")
    public String edit(@PathVariable("areaId") Long areaId, ModelMap mmap)
    {
        TbArea tbArea = tbAreaService.selectTbAreaByAreaId(areaId);
        mmap.put("tbArea", tbArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存地区

     */
    @RequiresPermissions("business:area:edit")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbArea tbArea)
    {
        return toAjax(tbAreaService.updateTbArea(tbArea));
    }

    /**
     * 删除地区

     */
    @RequiresPermissions("business:area:remove")
    @Log(title = "地区", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbAreaService.deleteTbAreaByAreaIds(ids));
    }
}
