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.IsLotoSwitchMap;
import com.ktg.iscs.domain.dto.point.SwitchBindingPointDTO;
import com.ktg.iscs.domain.vo.loto.IsLotoSwitchMapVO;
import com.ktg.iscs.service.IIsLotoSwitchMapService;
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-08-21
 */
@Api(tags = "开关布局")
@RestController
@RequestMapping("/iscs/switchmap")
public class IsLotoSwitchMapController extends BaseController
{
    @Autowired
    private IIsLotoSwitchMapService isLotoSwitchMapService;

    @ApiOperation("查询开关布局-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isLotoSwitchMap", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:list')")
    @GetMapping("/getIsLotoSwitchMapPage")
    public CommonResult<Page<IsLotoSwitchMapVO>> getIsLotoSwitchMapPage(Page<IsLotoSwitchMap> page, IsLotoSwitchMap isLotoSwitchMap)
    {
        Page<IsLotoSwitchMapVO> result = isLotoSwitchMapService.getIsLotoSwitchMapPage(page, isLotoSwitchMap);
        return CommonResult.success(result);
    }

    @ApiOperation("导出开关布局列表")
    @Parameter(name = "isLotoSwitchMap", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:export')")
    @Log(title = "开关布局", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsLotoSwitchMap")
    public void exportIsLotoSwitchMap(HttpServletResponse response, IsLotoSwitchMap isLotoSwitchMap)
    {
        Page<IsLotoSwitchMap> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsLotoSwitchMap> list = isLotoSwitchMapService.page(page, Wrappers.<IsLotoSwitchMap>lambdaQuery()
                .orderByDesc(IsLotoSwitchMap::getSwitchMapId)).getRecords();
        ExcelUtil<IsLotoSwitchMap> util = new ExcelUtil<IsLotoSwitchMap>(IsLotoSwitchMap.class);
        util.exportExcel(response, list, "开关布局数据");
    }

    @ApiOperation("获取开关布局详细信息")
    @Parameter(name = "switchMapId", description = "switchMapId")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:query')")
    @GetMapping(value = "/selectIsLotoSwitchMapById")
    public CommonResult<IsLotoSwitchMap> selectIsLotoSwitchMapById(Long switchMapId)
    {
        return CommonResult.success(isLotoSwitchMapService.selectIsLotoSwitchMapById(switchMapId));
    }

    @ApiOperation("获取开关布局详细信息")
    @Parameter(name = "serialNumber", description = "serialNumber")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:query')")
    @GetMapping(value = "/selectSwitchMapBySerialNumber")
    public CommonResult<IsLotoSwitchMap> selectSwitchMapBySerialNumber(String serialNumber)
    {
        return CommonResult.success(isLotoSwitchMapService.selectSwitchMapBySerialNumber(serialNumber));
    }

    @ApiOperation("新增开关布局")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:add')")
    @Log(title = "开关布局", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsLotoSwitchMap")
    public CommonResult<Boolean> insertIsLotoSwitchMap(@RequestBody @Parameter(name = "isLotoSwitchMap", description = "新增数据类,放到body") IsLotoSwitchMap isLotoSwitchMap)
    {
        return CommonResult.success(isLotoSwitchMapService.insertIsLotoSwitchMap(isLotoSwitchMap));
    }

    @ApiOperation("修改开关布局")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:edit')")
    @Log(title = "开关布局", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsLotoSwitchMap")
    public CommonResult<Boolean> updateIsLotoSwitchMap(@RequestBody @Parameter(name = "isLotoSwitchMap", description = "修改数据类,放到body") IsLotoSwitchMap isLotoSwitchMap)
    {
        return CommonResult.success(isLotoSwitchMapService.updateIsLotoSwitchMap(isLotoSwitchMap));
    }

    @ApiOperation("删除开关布局")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:remove')")
    @Log(title = "开关布局", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsLotoSwitchMapBySwitchMapIds")
    public CommonResult<Boolean> deleteIsLotoSwitchMapBySwitchMapIds(String switchMapIds)
    {
        Assert.notBlank(switchMapIds, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(switchMapIds);
        return CommonResult.success(isLotoSwitchMapService.removeBatchByIds(Arrays.asList(longIds)));
    }

    @ApiOperation("隔离点绑定/解绑开关布局")
    @PreAuthorize("@ss.hasPermi('iscs:switchmap:edit')")
    @Log(title = "开关布局", businessType = BusinessType.UPDATE)
    @PostMapping("/updatePointsBindingSwitchMap")
    public CommonResult<Boolean> updatePointsBindingSwitchMap(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") SwitchBindingPointDTO dto)
    {
        return CommonResult.success(isLotoSwitchMapService.updatePointsBindingSwitchMap(dto));
    }

}
