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.IsMapPoint;
import com.ktg.iscs.domain.dto.mapPoint.MapPointParamDTO;
import com.ktg.iscs.service.IIsMapPointService;
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-point")
public class IsMapPointController extends BaseController
{
    @Autowired
    private IIsMapPointService isMapPointService;

    @ApiOperation("查询地图点位数据-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMapPoint", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:map-point:list')")
    @GetMapping("/getIsMapPointPage")
    public CommonResult<Page<IsMapPoint>> getIsMapPointPage(Page<IsMapPoint> page, IsMapPoint isMapPoint)
    {
        Page<IsMapPoint> result = isMapPointService.getIsMapPointPage(page, isMapPoint);
        return CommonResult.success(result);
    }

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

    @ApiOperation("获取地图点位数据详细信息")
    @Parameter(name = "id", description = "id")
    @PreAuthorize("@ss.hasPermi('iscs:map-point:query')")
    @GetMapping(value = "/selectIsMapPointById")
    public CommonResult<IsMapPoint> selectIsMapPointById(Long id)
    {
        return CommonResult.success(isMapPointService.getById(id));
    }

    @ApiOperation("新增地图点位数据")
    @PreAuthorize("@ss.hasPermi('iscs:map-point:add')")
    @Log(title = "地图点位数据", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMapPoint")
    public CommonResult<Boolean> insertIsMapPoint(@RequestBody @Parameter(name = "isMapPoint", description = "新增数据类,放到body") IsMapPoint isMapPoint)
    {
        return CommonResult.success(isMapPointService.save(isMapPoint));
    }

    @ApiOperation("修改地图点位数据")
    @PreAuthorize("@ss.hasPermi('iscs:map-point:edit')")
    @Log(title = "地图点位数据", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMapPoint")
    public CommonResult<Boolean> updateIsMapPoint(@RequestBody @Parameter(name = "isMapPoint", description = "修改数据类,放到body") IsMapPoint isMapPoint)
    {
        return CommonResult.success(isMapPointService.updateById(isMapPoint));
    }

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

    @ApiOperation("地图点位数据变更(绑定，位移，解绑)")
    @PreAuthorize("@ss.hasPermi('iscs:map-point:add')")
    @Log(title = "地图点位数据变更(绑定，位移，解绑)", businessType = BusinessType.INSERT)
    @PostMapping("/updateMapPointList")
    public CommonResult<Boolean> updateMapPointList(@RequestBody @Parameter(name = "isMapPoint", description = "新增数据类,放到body") MapPointParamDTO dto)
    {
        return CommonResult.success(isMapPointService.updateMapPointList(dto));
    }

}
