package com.ruoyi.system.controller;

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

/**
 * 自定义地区Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/DiyCity")
public class DiyCityController extends BaseController
{
    @Autowired
    private IDiyCityService diyCityService;

    /**
     * 查询自定义地区列表
     */
    @PreAuthorize("@ss.hasPermi('system:DiyCity:list')")
    @GetMapping("/list")
    public TableDataInfo list(DiyCity diyCity)
    {
        startPage();
        List<DiyCity> list = diyCityService.selectDiyCityList(diyCity);
        return getDataTable(list);
    }

    /**
     * 导出自定义地区列表
     */
    @PreAuthorize("@ss.hasPermi('system:DiyCity:export')")
    @Log(title = "自定义地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DiyCity diyCity)
    {
        List<DiyCity> list = diyCityService.selectDiyCityList(diyCity);
        ExcelUtil<DiyCity> util = new ExcelUtil<DiyCity>(DiyCity.class);
        util.exportExcel(response, list, "自定义地区数据");
    }

    /**
     * 获取自定义地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:DiyCity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(diyCityService.selectDiyCityById(id));
    }

    /**
     * 新增自定义地区
     */
    @PreAuthorize("@ss.hasPermi('system:DiyCity:add')")
    @Log(title = "自定义地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DiyCity diyCity)
    {
        return toAjax(diyCityService.insertDiyCity(diyCity));
    }

    /**
     * 修改自定义地区
     */
    @PreAuthorize("@ss.hasPermi('system:DiyCity:edit')")
    @Log(title = "自定义地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiyCity diyCity)
    {
        return toAjax(diyCityService.updateDiyCity(diyCity));
    }

    /**
     * 删除自定义地区
     */
    @PreAuthorize("@ss.hasPermi('system:DiyCity:remove')")
    @Log(title = "自定义地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(diyCityService.deleteDiyCityByIds(ids));
    }
}
