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.flexiblejob.AddFlexibleJobDTO;
import com.ktg.iscs.domain.dto.flexiblejob.KeyTakeDTO;
import com.ktg.iscs.domain.dto.hardwareApi.ParamDTO;
import com.ktg.iscs.service.FlexibleJobService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 灵活作业调用接口
 *
 * @author cgj
 * @date 2025-11-10
 */
@Api(tags = "灵活作业调用接口")
@RestController
@RequestMapping("/iscs/flexible-job")
public class FlexibleJobController extends BaseController
{
    @Autowired
    private FlexibleJobService flexibleJobService;

    // ----------------------------------新建作业-------------------------------------------------------
    @ApiOperation("灵活作业-新增")
    @Log(title = "灵活作业票", businessType = BusinessType.INSERT)
    @PostMapping("/insertFlexibleJobTicket")
    public CommonResult<Long> insertFlexibleJobTicket(@RequestBody @Parameter(name = "dto", description = "新增数据类,放到body") AddFlexibleJobDTO dto) {
        return CommonResult.success(flexibleJobService.insertFlexibleJobTicket(dto));
    }

    @ApiOperation("灵活作业-取出钥匙")
    @Log(title = "灵活作业票", businessType = BusinessType.INSERT)
    @PostMapping("/insertTakeOutKey")
    public CommonResult<Boolean> insertTakeOutKey(@RequestBody @Parameter(name = "dto", description = "新增数据类,放到body") KeyTakeDTO dto) {
        return CommonResult.success(flexibleJobService.insertTakeOutKey(dto.getList()));
    }

    @ApiOperation("灵活作业-归还钥匙")
    @Log(title = "灵活作业票", businessType = BusinessType.INSERT)
    @PostMapping("/updateTakeBackKey")
    public CommonResult<Boolean> updateTakeBackKey(@RequestBody @Parameter(name = "dto", description = "新增数据类,放到body") KeyTakeDTO dto) {
        return CommonResult.success(flexibleJobService.updateTakeBackKey(dto.getList()));
    }

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

    @ApiOperation("灵活作业-归还挂锁")
    @Log(title = "灵活作业", businessType = BusinessType.UPDATE)
    @PostMapping("/updateTakeBackLock")
    public CommonResult<Boolean> updateTakeBackLock(@RequestBody @Parameter(name = "list", description = "修改数据类,放到body") ParamDTO dto)
    {
        return CommonResult.success(flexibleJobService.updateTakeBackLock(dto.getList()));
    }

}
