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.IsTicketOperLog;
import com.ktg.iscs.service.IIsTicketOperLogService;
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;
import java.util.Arrays;




import com.ktg.common.core.page.TableDataInfo;

/**
 * 作业操作过程Controller
 *
 * @author cgj
 * @date 2025-07-14
 */
@Api(tags = "作业操作过程")
@RestController
@RequestMapping("/iscs/log")
public class IsTicketOperLogController extends BaseController
{
    @Autowired
    private IIsTicketOperLogService isTicketOperLogService;

    @ApiOperation("查询作业操作过程-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isTicketOperLog", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:log:list')")
    @GetMapping("/getIsTicketOperLogPage")
    public CommonResult<Page<IsTicketOperLog>> getIsTicketOperLogPage(Page<IsTicketOperLog> page, IsTicketOperLog isTicketOperLog)
    {
        Page<IsTicketOperLog> result = isTicketOperLogService.getIsTicketOperLogPage(page, isTicketOperLog);
        return CommonResult.success(result);
    }

    @ApiOperation("导出作业操作过程列表")
    @Parameter(name = "isTicketOperLog", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:log:export')")
    @Log(title = "作业操作过程", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsTicketOperLog")
    public void exportIsTicketOperLog(HttpServletResponse response, IsTicketOperLog isTicketOperLog)
    {
        Page<IsTicketOperLog> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsTicketOperLog> list = isTicketOperLogService.page(page, Wrappers.<IsTicketOperLog>lambdaQuery()
                .orderByDesc(IsTicketOperLog::getOperationId)).getRecords();
        ExcelUtil<IsTicketOperLog> util = new ExcelUtil<IsTicketOperLog>(IsTicketOperLog.class);
        util.exportExcel(response, list, "作业操作过程数据");
    }

    @ApiOperation("获取作业操作过程详细信息")
    @Parameter(name = "operationId", description = "operationId")
    @PreAuthorize("@ss.hasPermi('iscs:log:query')")
    @GetMapping(value = "/selectIsTicketOperLogById")
    public CommonResult<IsTicketOperLog> selectIsTicketOperLogById(Long operationId)
    {
        return CommonResult.success(isTicketOperLogService.getById(operationId));
    }

    @ApiOperation("新增作业操作过程")
    @PreAuthorize("@ss.hasPermi('iscs:log:add')")
    @Log(title = "作业操作过程", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsTicketOperLog")
    public CommonResult<Boolean> insertIsTicketOperLog(@RequestBody @Parameter(name = "isTicketOperLog", description = "新增数据类,放到body") IsTicketOperLog isTicketOperLog)
    {
        return CommonResult.success(isTicketOperLogService.save(isTicketOperLog));
    }

    @ApiOperation("修改作业操作过程")
    @PreAuthorize("@ss.hasPermi('iscs:log:edit')")
    @Log(title = "作业操作过程", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsTicketOperLog")
    public CommonResult<Boolean> updateIsTicketOperLog(@RequestBody @Parameter(name = "isTicketOperLog", description = "修改数据类,放到body") IsTicketOperLog isTicketOperLog)
    {
        return CommonResult.success(isTicketOperLogService.updateById(isTicketOperLog));
    }

    @ApiOperation("删除作业操作过程")
    @PreAuthorize("@ss.hasPermi('iscs:log:remove')")
    @Log(title = "作业操作过程", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsTicketOperLogByOperationIds")
    public CommonResult<Boolean> deleteIsTicketOperLogByOperationIds(String operationIds)
    {
        Assert.notBlank(operationIds, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(operationIds);
        return CommonResult.success(isTicketOperLogService.removeBatchByIds(Arrays.asList(longIds)));
    }
}
