package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ss.city.domain.CityCode;
import com.ruoyi.ss.city.service.ICityCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 城市区号Controller
 *
 * @author qzz
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/system/code")
public class CityCodeController extends BaseController
{
    @Autowired
    private ICityCodeService rlCityCodeService;

    /**
     * 查询城市区号列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityCode rlCityCode)
    {
        startPage();
        List<CityCode> list = rlCityCodeService.selectRlCityCodeList(rlCityCode);
        return getDataTable(list);
    }

    /**
     * 导出城市区号列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:export')")
    @Log(title = "城市区号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityCode rlCityCode)
    {
        List<CityCode> list = rlCityCodeService.selectRlCityCodeList(rlCityCode);
        ExcelUtil<CityCode> util = new ExcelUtil<CityCode>(CityCode.class);
        util.exportExcel(response, list, "城市区号数据");
    }

    /**
     * 获取城市区号详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:code:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(rlCityCodeService.selectRlCityCodeByCode(code));
    }

    /**
     * 新增城市区号
     */
    @PreAuthorize("@ss.hasPermi('system:code:add')")
    @Log(title = "城市区号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityCode rlCityCode)
    {
        return toAjax(rlCityCodeService.insertRlCityCode(rlCityCode));
    }

    /**
     * 修改城市区号
     */
    @PreAuthorize("@ss.hasPermi('system:code:edit')")
    @Log(title = "城市区号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityCode rlCityCode)
    {
        return toAjax(rlCityCodeService.updateRlCityCode(rlCityCode));
    }

    /**
     * 删除城市区号
     */
    @PreAuthorize("@ss.hasPermi('system:code:remove')")
    @Log(title = "城市区号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable Long[] codes)
    {
        return toAjax(rlCityCodeService.deleteRlCityCodeByCodeIds(codes));
    }
}
