package com.ktg.iscs.controller;

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.iscs.domain.dto.exUpdate.ExDTO;
import com.ktg.iscs.domain.dto.hardwareApi.*;
import com.ktg.iscs.domain.vo.hardwareApi.JobTicketVO;
import com.ktg.iscs.service.HardwareApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 硬件调用接口
 *
 * @author cgj
 * @date 2024-10-16
 */
@Api(tags = "硬件调用接口")
@RestController
@RequestMapping("/iscs/hardware-api")
public class HardwareApiController extends BaseController
{
    @Autowired
    private HardwareApiService hardwareApiService;

    // ----------------------------------作业票取还钥匙-------------------------------------------------------
    @ApiOperation("取出钥匙")
    @Log(title = "取出钥匙", businessType = BusinessType.UPDATE)
    @PostMapping("/updateTakeOutKey")
    public CommonResult<Boolean> updateTakeOutKey(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") TakeOutKeyDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateTakeOutKey(dto));
    }

    @ApiOperation("归还钥匙")
    @Log(title = "归还钥匙", businessType = BusinessType.UPDATE)
    @PostMapping("/updateReturnKey")
    public CommonResult<Boolean> updateReturnKey(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") ReturnKeyDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateReturnKey(dto));
    }


    // ----------------------------------作业票取还挂锁-------------------------------------------------------
    @ApiOperation("取出挂锁时更新数据")
    @Log(title = "取出挂锁时更新数据", businessType = BusinessType.UPDATE)
    @PostMapping("/updateTicketLockTake")
    public CommonResult<Boolean> updateTicketLockTake(@RequestBody @Parameter(name = "list", description = "修改数据类,放到body") ParamDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateTicketLockTake(dto.getList()));
    }

    @ApiOperation("归还挂锁时更新数据")
    @Log(title = "归还挂锁时更新数据", businessType = BusinessType.UPDATE)
    @PostMapping("/updateTicketLockReturn")
    public CommonResult<Boolean> updateTicketLockReturn(@RequestBody @Parameter(name = "list", description = "修改数据类,放到body") ReturnTicketLockDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateTicketLockReturn(dto));
    }

    @ApiOperation("批量更新作业票下隔离点的上锁状况")
    @Log(title = "批量更新作业票下隔离点的上锁状况", businessType = BusinessType.UPDATE)
    @PostMapping("/updateLockPointBatch")
    public CommonResult<Boolean> updateLockPointBatch(@RequestBody @Parameter(name = "list", description = "修改数据类,放到body") LPBParamDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateLockPointBatch(dto.getList()));
    }


    // ----------------------------------作业票取还辅件-------------------------------------------------------
    @ApiOperation("取出辅件时更新数据")
    @Log(title = "取出辅件时更新数据", businessType = BusinessType.UPDATE)
    @PostMapping("/updateLocksetTake")
    public CommonResult<Boolean> updateLocksetTake(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") LTParamDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateLocksetTake(dto.getList()));
    }

    @ApiOperation("辅件绑定隔离点(辅件和给隔离点上锁时)")
    @Log(title = "辅件绑定隔离点", businessType = BusinessType.UPDATE)
    @PostMapping("/updateLocksetPoint")
    public CommonResult<Boolean> updateLocksetPoint(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") LocksetPointDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateLocksetPoint(dto));
    }

    @ApiOperation("辅件归还物资柜")
    @Log(title = "辅件归还物资柜", businessType = BusinessType.UPDATE)
    @PostMapping("/updateLocksetReturn")
    public CommonResult<Boolean> updateLocksetReturn(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") ReturnLocksetDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateLocksetReturn(dto));
    }

    // ----------------------------------作业票及作业票的相关数据查询-------------------------------------------------------
    @ApiOperation("获取作业票和关联数据")
    @Parameter(name = "ticketId", description = "ticketId")
    @GetMapping(value = "/selectTicketDetailById")
    public CommonResult<JobTicketVO> selectTicketDetailById(Long ticketId)
    {
        return CommonResult.success(hardwareApiService.selectTicketDetailById(ticketId));
    }

    // 共锁人上锁/解锁
    @ApiOperation("共锁人上锁/解锁")
    @Log(title = "共锁人上锁/解锁", businessType = BusinessType.UPDATE)
    @PostMapping("/updateColockerStatus")
    public CommonResult<Boolean> updateColockerStatus(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") UpdateColockerStatusDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateColockerStatus(dto));
    }

    @ApiOperation("批量更新隔离点开关状态")
    // @Log(title = "批量更新隔离点开关状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateSwitchList")
    public CommonResult<Integer> updateSwitchList(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") UpdateSwitchParam dto)
    {
        return CommonResult.success(hardwareApiService.updateSwitchList(dto));
    }

    // ----------------------------------作业票及作业票的相关数据查询-------------------------------------------------------

    @ApiOperation("上锁取钥匙前检查")
    @Parameter(name = "ticketId", description = "ticketId")
    @GetMapping(value = "/checkBeforeToLock")
    public CommonResult<Boolean> checkBeforeToLock(Long ticketId)
    {
        return CommonResult.success(hardwareApiService.checkBeforeToLock(ticketId));
    }

    @ApiOperation("解锁取钥匙前检查")
    @Parameter(name = "ticketId", description = "ticketId")
    @GetMapping(value = "/checkBeforeToUnlock")
    public CommonResult<Boolean> checkBeforeToUnlock(Long ticketId)
    {
        return CommonResult.success(hardwareApiService.checkBeforeToUnlock(ticketId));
    }

    @ApiOperation("重合点位数据解锁")
    @Log(title = "重合点位数据解锁", businessType = BusinessType.UPDATE)
    @PostMapping("/updateCoincideToUnLock")
    public CommonResult<Boolean> updateCoincideToUnLock(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") CoincidePointToUnLockDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateCoincideToUnLock(dto));
    }

    // ----------------------------------批量更新硬件状态-------------------------------------------------------
    @ApiOperation("批量更新硬件状态")
    @Log(title = "批量更新硬件状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateHardwareEsStatus")
    public CommonResult<Boolean> updateHardwareEsStatus(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") ExDTO dto)
    {
        return CommonResult.success(hardwareApiService.updateHardwareEsStatus(dto));
    }

    // ----------------------------------判断当前登陆人员是否有需要去上所或者去解锁的需求-------------------------------------------------------
    @ApiOperation("判断当前登陆人员是否有需要去上所或者去解锁的需求")
    @GetMapping(value = "/getMySelfState")
    public CommonResult<Boolean> getMySelfState()
    {
        return CommonResult.success(hardwareApiService.getMySelfState());
    }

    @ApiOperation("判断当前锁还入时能不能锁")
    @GetMapping(value = "/getLockStateByNfc")
    public CommonResult<Integer> getLockStateByNfc(String nfc)
    {
        return CommonResult.success(hardwareApiService.getLockStateByNfc(nfc, null));
    }


}
