package com.ruoyi.web.controller.projectV2.common;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.projectV2.common.ChinaArea;
import com.ruoyi.system.service.projectV2.common.IChinaAreaService;
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.common.core.page.TableDataInfo;

/**
 * 中国行政规划Controller
 * 
 * @author boman
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/projectV2/area")
public class ChinaAreaController extends BaseController
{
    @Autowired
    private IChinaAreaService chinaAreaService;

    /**
     * 查询中国行政规划列表
     */
    @PreAuthorize("@ss.hasPermi('projectV2:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChinaArea chinaArea)
    {
        startPage();
        List<ChinaArea> list = chinaAreaService.selectChinaAreaList(chinaArea);
        return getDataTable(list);
    }

    /**
     * 导出中国行政规划列表
     */
    @PreAuthorize("@ss.hasPermi('projectV2:area:export')")
    @Log(title = "中国行政规划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChinaArea chinaArea)
    {
        List<ChinaArea> list = chinaAreaService.selectChinaAreaList(chinaArea);
        ExcelUtil<ChinaArea> util = new ExcelUtil<ChinaArea>(ChinaArea.class);
        util.exportExcel(response, list, "中国行政规划数据");
    }

    /**
     * 获取中国行政规划详细信息
     */
    @PreAuthorize("@ss.hasPermi('projectV2:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") String areaId)
    {
        return success(chinaAreaService.selectChinaAreaByAreaId(areaId));
    }

    /**
     * 新增中国行政规划
     */
    @PreAuthorize("@ss.hasPermi('projectV2:area:add')")
    @Log(title = "中国行政规划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChinaArea chinaArea)
    {
        return toAjax(chinaAreaService.insertChinaArea(chinaArea));
    }

    /**
     * 修改中国行政规划
     */
    @PreAuthorize("@ss.hasPermi('projectV2:area:edit')")
    @Log(title = "中国行政规划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChinaArea chinaArea)
    {
        return toAjax(chinaAreaService.updateChinaArea(chinaArea));
    }

    /**
     * 删除中国行政规划
     */
    @PreAuthorize("@ss.hasPermi('projectV2:area:remove')")
    @Log(title = "中国行政规划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable String[] areaIds)
    {
        return toAjax(chinaAreaService.deleteChinaAreaByAreaIds(areaIds));
    }
}
