package com.ruoyi.web.controller.system;

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.TRegion;
import com.ruoyi.system.service.ITRegionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行政区域Controller
 * 
 * @author zhengjie
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/system/region")
public class TRegionController extends BaseController
{
    @Autowired
    private ITRegionService tRegionService;

    /**
     * 查询行政区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRegion tRegion)
    {
        startPage();
        List<TRegion> list = tRegionService.selectTRegionList(tRegion);
        return getDataTable(list);
    }

    /**
     * 导出行政区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:export')")
    @Log(title = "行政区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRegion tRegion)
    {
        List<TRegion> list = tRegionService.selectTRegionList(tRegion);
        ExcelUtil<TRegion> util = new ExcelUtil<TRegion>(TRegion.class);
        util.exportExcel(response, list, "行政区域数据");
    }

    /**
     * 获取行政区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tRegionService.selectTRegionById(id));
    }

    /**
     * 新增行政区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:add')")
    @Log(title = "行政区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRegion tRegion)
    {
        return toAjax(tRegionService.insertTRegion(tRegion));
    }

    /**
     * 修改行政区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:edit')")
    @Log(title = "行政区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRegion tRegion)
    {
        return toAjax(tRegionService.updateTRegion(tRegion));
    }

    /**
     * 删除行政区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:remove')")
    @Log(title = "行政区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tRegionService.deleteTRegionByIds(ids));
    }
}
