package com.weather.modules.region.controller;

import com.weather.common.annotation.LogOperation;
import com.weather.common.constant.Constant;
import com.weather.common.page.PageData;
import com.weather.common.utils.ExcelUtils;
import com.weather.common.utils.Result;
import com.weather.common.validator.AssertUtils;
import com.weather.common.validator.ValidatorUtils;
import com.weather.common.validator.group.AddGroup;
import com.weather.common.validator.group.DefaultGroup;
import com.weather.common.validator.group.UpdateGroup;
import com.weather.modules.region.dto.SysRegionDTO;
import com.weather.modules.region.excel.SysRegionExcel;
import com.weather.modules.region.service.SysRegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 行政区划表
 *
 * @author Mark 123
 * @since 1.0.0 2026-03-05
 */
@RestController
@RequestMapping("region/sysregion")
@Tag(name="行政区划表")
public class SysRegionController {

    @Autowired
    private SysRegionService sysRegionService;

    @GetMapping("parent/{id}")
    @Operation(summary = "信息")
    @RequiresPermissions("region:sysregion:info")
    public Result<List<SysRegionDTO>> get(@PathVariable Long id){
        List<SysRegionDTO> data = sysRegionService.getByParentId(id);
        return new Result<List<SysRegionDTO>>().ok(data);
    }

    @GetMapping("export")
    @Operation(summary = "导出")
    @LogOperation("导出")
    @RequiresPermissions("region:sysregion:export")
    public void export(@Parameter(hidden = true) @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<SysRegionDTO> list = sysRegionService.list(params);

        ExcelUtils.exportExcelToTarget(response, null, "行政区划表", list, SysRegionExcel.class);
    }

}
