package com.ktg.iscs.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.IsMap;
import com.ktg.iscs.service.IIsMapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
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.Arrays;
import java.util.List;

/**
 * 地图参数Controller
 *
 * @author cgj
 * @date 2025-03-11
 */
@Api(tags = "地图参数")
@RestController
@RequestMapping("/iscs/map")
public class IsMapController extends BaseController
{
    @Autowired
    private IIsMapService isMapService;

    @ApiOperation("查询地图参数-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMap", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:map:list')")
    @GetMapping("/getIsMapPage")
    public CommonResult<Page<IsMap>> getIsMapPage(Page<IsMap> page, IsMap isMap)
    {
        Page<IsMap> result = isMapService.getIsMapPage(page, isMap);
        return CommonResult.success(result);
    }

    @ApiOperation("导出地图参数列表")
    @Parameter(name = "isMap", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:map:export')")
    @Log(title = "地图参数", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMap")
    public void exportIsMap(HttpServletResponse response, IsMap isMap)
    {
        Page<IsMap> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsMap> list = isMapService.page(page, Wrappers.<IsMap>lambdaQuery()
                .orderByDesc(IsMap::getId)).getRecords();
        ExcelUtil<IsMap> util = new ExcelUtil<IsMap>(IsMap.class);
        util.exportExcel(response, list, "地图参数数据");
    }

    @ApiOperation("获取地图参数详细信息")
    @Parameter(name = "id", description = "id")
    // @PreAuthorize("@ss.hasPermi('iscs:map:query')")
    @GetMapping(value = "/selectIsMapById")
    public CommonResult<IsMap> selectIsMapById(Long id)
    {
        return CommonResult.success(isMapService.selectIsMapById(id));
    }

    @ApiOperation("新增地图参数")
    @PreAuthorize("@ss.hasPermi('iscs:map:add')")
    @Log(title = "地图参数", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMap")
    public CommonResult<Boolean> insertIsMap(@RequestBody @Parameter(name = "isMap", description = "新增数据类,放到body") IsMap isMap)
    {
        return CommonResult.success(isMapService.save(isMap));
    }

    @ApiOperation("修改地图参数")
    @PreAuthorize("@ss.hasPermi('iscs:map:edit')")
    @Log(title = "地图参数", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMap")
    public CommonResult<Boolean> updateIsMap(@RequestBody @Parameter(name = "isMap", description = "修改数据类,放到body") IsMap isMap)
    {
        return CommonResult.success(isMapService.updateById(isMap));
    }

    @ApiOperation("删除地图参数")
    @PreAuthorize("@ss.hasPermi('iscs:map:remove')")
    @Log(title = "地图参数", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMapByIds")
    public CommonResult<Boolean> deleteIsMapByIds(String ids)
    {
        Assert.notBlank(ids, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(ids);
        return CommonResult.success(isMapService.removeBatchByIds(Arrays.asList(longIds)));
    }
}
