package com.ruoyi.logistics.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.logistics.domain.SysCity;
import com.ruoyi.logistics.service.ISysCityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * PC-城市管理
 * 
 * @author RuiJing
 * @date 2026-01-29
 */
@RestController
@RequestMapping("/city")
public class SysCityController extends BaseController
{
    @Autowired
    private ISysCityService sysCityService;

    /**
     * 查询城市管理列表
     */
    @RequiresPermissions("system:city:list")
    @GetMapping("/list")
    public TableDataInfo list(SysCity sysCity)
    {
        startPage();
        List<SysCity> list = sysCityService.selectSysCityList(sysCity);
        return getDataTable(list);
    }

    /**
     * 导出城市管理列表
     */
    @RequiresPermissions("system:city:export")
    @Log(title = "城市管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCity sysCity)
    {
        List<SysCity> list = sysCityService.selectSysCityList(sysCity);
        ExcelUtil<SysCity> util = new ExcelUtil<SysCity>(SysCity.class);
        util.exportExcel(response, list, "城市管理数据");
    }

    /**
     * 获取城市管理详细信息
     */
    @RequiresPermissions("system:city:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysCityService.selectSysCityById(id));
    }

    /**
     * 新增城市管理
     */
    @RequiresPermissions("system:city:add")
    @Log(title = "城市管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCity sysCity)
    {
        return toAjax(sysCityService.insertSysCity(sysCity));
    }

    /**
     * 修改城市管理
     */
    @RequiresPermissions("system:city:edit")
    @Log(title = "城市管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCity sysCity)
    {
        return toAjax(sysCityService.updateSysCity(sysCity));
    }

    /**
     * 删除城市管理
     */
    @RequiresPermissions("system:city:remove")
    @Log(title = "城市管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCityService.deleteSysCityByIds(ids));
    }
}
