package com.ktg.iscs.controller;

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.IsIsolationPoint;
import com.ktg.iscs.domain.dto.point.PagePointDTO;
import com.ktg.iscs.domain.vo.points.PointDetailVO;
import com.ktg.iscs.domain.vo.points.PointPageVO;
import com.ktg.iscs.service.IIsIsolationPointService;
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.List;

/**
 * 隔离点Controller
 *
 * @author cgj
 * @date 2024-10-18
 */
@Api(tags = "隔离点")
@RestController
@RequestMapping("/iscs/point")
public class IsIsolationPointController extends BaseController {
    @Autowired
    private IIsIsolationPointService isIsolationPointService;

    /**
     * 查询隔离点分页
     */
    @ApiOperation("查询隔离点-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "dto", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:point:list')")
    @GetMapping("/getIsIsolationPointPage")
    public CommonResult<Page<PointPageVO>> getIsIsolationPointPage(Page<IsIsolationPoint> page, PagePointDTO dto) {
        Page<PointPageVO> result = isIsolationPointService.getIsIsolationPointPage(page, dto);
        return CommonResult.success(result);
    }

    @ApiOperation("查询隔离点-列表")
    @Parameters({
            @Parameter(name = "workshopId", description = "所属车间ID"),
            @Parameter(name = "workareaId", description = "所属区域ID")
    })
    @PreAuthorize("@ss.hasPermi('iscs:point:list')")
    @GetMapping("/getIsIsolationPointList")
    public CommonResult<List<IsIsolationPoint>> getIsIsolationPointList(Long workshopId, Long workareaId) {
        List<IsIsolationPoint> result = isIsolationPointService.getIsIsolationPointList(workshopId, workareaId);
        return CommonResult.success(result);
    }

    /**
     * 导出隔离点列表
     */
    @ApiOperation("导出隔离点列表")
    @Parameter(name = "isIsolationPoint", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:point:export')")
    @Log(title = "隔离点", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsIsolationPoint")
    public void exportIsIsolationPoint(HttpServletResponse response, IsIsolationPoint isIsolationPoint) {
        List<IsIsolationPoint> list = isIsolationPointService.selectIsIsolationPointList(isIsolationPoint);
        ExcelUtil<IsIsolationPoint> util = new ExcelUtil<IsIsolationPoint>(IsIsolationPoint.class);
        util.exportExcel(response, list, "隔离点数据");
    }

    /**
     * 获取隔离点详细信息
     */
    @ApiOperation("获取隔离点详细信息")
    @Parameter(name = "pointId", description = "pointId")
    @PreAuthorize("@ss.hasPermi('iscs:point:query')")
    @GetMapping(value = "/selectIsIsolationPointById")
    public CommonResult<PointDetailVO> selectIsIsolationPointById(Long pointId) {
        return CommonResult.success(isIsolationPointService.selectIsIsolationPointByPointId(pointId));
    }

    /**
     * 新增隔离点
     */
    @ApiOperation("新增隔离点")
    @PreAuthorize("@ss.hasPermi('iscs:point:add')")
    @Log(title = "隔离点", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsIsolationPoint")
    public CommonResult<Boolean> insertIsIsolationPoint(@RequestBody @Parameter(name = "isIsolationPoint", description = "新增数据类,放到body") IsIsolationPoint isIsolationPoint) {
        return CommonResult.success(isIsolationPointService.insertIsIsolationPoint(isIsolationPoint) == 1);
    }

    /**
     * 修改隔离点
     */
    @ApiOperation("修改隔离点")
    @PreAuthorize("@ss.hasPermi('iscs:point:edit')")
    @Log(title = "隔离点", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsIsolationPoint")
    public CommonResult<Boolean> updateIsIsolationPoint(@RequestBody @Parameter(name = "isIsolationPoint", description = "修改数据类,放到body") IsIsolationPoint isIsolationPoint) {
        return CommonResult.success(isIsolationPointService.updateIsIsolationPoint(isIsolationPoint) == 1);
    }

    /**
     * 删除隔离点
     */
    @ApiOperation("删除隔离点")
    @PreAuthorize("@ss.hasPermi('iscs:point:remove')")
    @Log(title = "隔离点", businessType = BusinessType.DELETE)
    @PostMapping("/deleteIsIsolationPointByPointIds")
    public CommonResult<Boolean> deleteIsIsolationPointByPointIds(String pointIds) {
        return CommonResult.success(isIsolationPointService.deleteIsIsolationPointByPointIds(pointIds) != 0);
    }
}
