package com.ruoyi.basic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.basic.domain.HwArea;
import com.ruoyi.basic.service.IHwAreaService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 区域管理Controller
 * 
 * @author YINQ
 * @date 2023-08-30
 */
@RestController
@RequestMapping("/area")
public class HwAreaController extends BaseController
{
    @Autowired
    private IHwAreaService hwAreaService;

    /**
     * 查询区域管理列表
     */
    @RequiresPermissions("basic:area:list")
    @GetMapping("/list")
    public AjaxResult list(HwArea hwArea)
    {
        List<HwArea> list = hwAreaService.selectHwAreaList(hwArea);
        return success(list);
    }

    /**
     * 导出区域管理列表
     */
    @RequiresPermissions("basic:area:export")
    @Log(title = "区域管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwArea hwArea)
    {
        List<HwArea> list = hwAreaService.selectHwAreaList(hwArea);
        ExcelUtil<HwArea> util = new ExcelUtil<HwArea>(HwArea.class);
        util.exportExcel(response, list, "区域管理数据");
    }

    /**
     * 获取区域管理详细信息
     */
    @RequiresPermissions("basic:area:query")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(hwAreaService.selectHwAreaByAreaId(areaId));
    }

    /**
     * 新增区域管理
     */
    @RequiresPermissions("basic:area:add")
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HwArea hwArea)
    {
        return toAjax(hwAreaService.insertHwArea(hwArea));
    }

    /**
     * 修改区域管理
     */
    @RequiresPermissions("basic:area:edit")
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwArea hwArea)
    {
        return toAjax(hwAreaService.updateHwArea(hwArea));
    }

    /**
     * 删除区域管理
     */
    @RequiresPermissions("basic:area:remove")
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(hwAreaService.deleteHwAreaByAreaIds(areaIds));
    }
}
